I'm making a simple ADT that has a method (Add3) that adds 3 to a given int. The code is shown below:
public class TestADT
{
private final int x;
public TestADT (int x)
{
this.x = x;
}
public static TestADT Add3(TestADT num)
{
int ex = (num.x + 3);
return (new TestADT(ex));
}
public String toString()
{
return(x + "");
}
public static void main(String[] args)
{
TestADT test = new TestADT(2);
System.out.println(Add3(test));
}
}
What I'm trying to do is create a JUnit test to check that the Add3 method is working correctly and so far I have this:
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Add3Test
{
private TestADT test;
private TestADT expected;
@Before
public void setUp() throws Exception
{
test = new TestADT(2);
expected = new TestADT(5);
}
@Test
public void test()
{
TestADT result = TestADT.Add3(test);
assertEquals(expected, result);
}
}
When I run the testing class it fails but I'm unsure why. If I print both values (expected & result) before running the test they both print 5.
I'm relatively new to JUnit and ADT's so I'm not quite sure if I'm doing any of this right. I'm going to try and find some tutorial videos on JUnit and see if I can figure out a solution. Any help would be appreciated!