forked from kepbautista/mycalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTesters.java
66 lines (55 loc) · 1.55 KB
/
MyTesters.java
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
import static org.junit.Assert.*;
import org.junit.Test;
public class MyTester {
@Test
public void testNfactorial() { //tests the factorial of 0
MyCalculator mc = new MyCalculator();
int n = mc.nfactorial(0);
assertEquals(n, 1);
}
@Test
public void testNfactorial1() { //tests the factorial of 1
MyCalculator mc = new MyCalculator();
int n = mc.nfactorial(1);
assertEquals(n, 1);
}
@Test
public void testNfactorial2() { //tests the factorial of 2
MyCalculator mc = new MyCalculator();
int n = mc.nfactorial(2);
assertEquals(n, 2);
}
@Test
public void testNfactorial3() { //tests the factorial of 3
MyCalculator mc = new MyCalculator();
int n = mc.nfactorial(3);
assertEquals(n, 6);
}
@Test
public void testBinarySearch() { //search for 1 in the array with 1 element
MyCalculator mc = new MyCalculator();
int[] a = {1};
int x = 1;
int pos;
pos = mc.binarySearch(a, x);
assertEquals(pos, 0); //returns 0 as the index of the number being searched
}
@Test
public void testBinarySearch1() { //search for 0 in the array with 1 element
MyCalculator mc = new MyCalculator();
int[] a = {1};
int x = 0;
int pos;
pos = mc.binarySearch(a, x); //returns 1 if the element search is not found
assertEquals(pos, 1);
}
@Test
public void testBinarySearch2() { //search for 5 in the array with 1 element
MyCalculator mc = new MyCalculator();
int[] a = {1, 2, 4, 3, 5};
int x = 5;
int pos;
pos = mc.binarySearch(a, x); //returns 4 as the index of the element being searched
assertEquals(pos, 4);
}
}