Question: Create a simple Java project named Assignment16. Create a class named Ackermann. Create a static method named ackermann which takes 2 int parameters, m and

Create a simple Java project named Assignment16.

Create a class named Ackermann.

Create a static method named ackermann which takes 2 int parameters, m and n. Use recursive logic to calculate a value as follows:

Ackermann(0, n) = n + 1

Ackermann(m, 0) = Ackermann(m 1, 1)

Ackermann(m, n) = Ackermann(m 1, Ackermann(m, n 1))

Create a Junit 5 testing class named AckermannTest.

Enter the code:

import org.junit.jupiter.api.DisplayName;

import org.junit.jupiter.params.ParameterizedTest;

import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AckermannTest {

@DisplayName("Ackermann Function Tests")

@ParameterizedTest(name="{index}=>m={0},n={1},ackermann={2}")

@CsvSource({"0,0,1", "0,1,2", "1,1,3", "1,2,4", "1,3,5", "2,2,7", "3,2,29"})

void ackermannTest(int m, int n, int ackermann) {

assertEquals(ackermann, Ackermann.ackermann(m, n));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!