-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursionTest.java
More file actions
152 lines (138 loc) · 3.28 KB
/
RecursionTest.java
File metadata and controls
152 lines (138 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* Unit tests for implementation of RecusionADT
*
* @author Jacob Boyles
* @version 1.0
*/
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Unit tests for MyRec
* @author jacobboyles
* @version 1.0
*/
public class RecursionTest {
/**
* Factorial test
*/
@Test
public void factorialTest() {
MyRec rec = new MyRec();
Integer input = 10;
Integer expected = 3628800;
Integer actual = rec.fact(input);
assertEquals(expected, actual);
}
/**
* Factorial test 0
*/
@Test
public void factorialTestZero() {
MyRec rec = new MyRec();
Integer zero = 0;
Integer one = 1;
assertEquals(one, rec.fact(zero));
}
/**
* Factorial test less than 0
*/
@Test
public void factorialLessThanZero() {
MyRec rec = new MyRec();
boolean throwsException = false;
Integer negativeOne = -1;
try {
rec.fact(negativeOne);
}
catch (IllegalArgumentException e) {
throwsException = true;
}
assertTrue(throwsException);
}
/**
* Palindrome test more than two characters
*/
@Test
public void palindromeTestMoreThanTwo() {
MyRec rec = new MyRec();
String s = "racecar";
boolean expected = true;
boolean actual = rec.isPal(s);
assertEquals(expected, actual);
}
/**
* Palindrome test less than two characters
*/
@Test
public void palindromeTestLessThanTwo() {
MyRec rec = new MyRec();
String s = "a";
boolean expected = true;
boolean actual = rec.isPal(s);
assertEquals(expected, actual);
}
/**
* Palindrome test not a palindrome
*/
@Test
public void palindromeTestFail() {
MyRec rec = new MyRec();
String s = "fail";
boolean expected = false;
boolean actual = rec.isPal(s);
assertEquals(expected, actual);
}
/**
* Is integer test with int
*/
@Test
public void isIntegerWithInt() {
MyRec rec = new MyRec();
String s = "123";
boolean expected = true;
boolean actual = rec.isInt(s);
assertEquals(expected, actual);
}
/**
* Is integer without int
*/
@Test
public void isIntegerWithoutInt() {
MyRec rec = new MyRec();
String s = "NotInt";
boolean expected = false;
boolean actual = rec.isInt(s);
assertEquals(expected, actual);
}
/**
* Is integer with '-' sign
*/
@Test
public void isIntegerWithMinus() {
MyRec rec = new MyRec();
String s = "-123";
boolean expected = true;
boolean actual = rec.isInt(s);
assertEquals(expected, actual);
}
/**
* Is integer with '+' sign
*/
@Test
public void isIntegerWithPlus() {
MyRec rec = new MyRec();
String s = "+123";
boolean expected = true;
boolean actual = rec.isInt(s);
assertEquals(expected, actual);
}
/**
* Is integer looking for fail
*/
@Test
public void isIntNotInt() {
MyRec rec = new MyRec();
String s = "fail";
boolean expected = false;
}
}