-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathGetNumberOfOccurrencesTest.java
More file actions
70 lines (57 loc) · 2.14 KB
/
GetNumberOfOccurrencesTest.java
File metadata and controls
70 lines (57 loc) · 2.14 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
package com.zipcodewilmington.arrayutility;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by leon on 3/1/18.
* The purpose of this class is to thoroughly test the method getNumberOfOccurrences()
*/
public class GetNumberOfOccurrencesTest {
@Test
public void integerTest() {
// Given
Integer valueToEvaluate = 7;
Integer expected = 3;
Integer[] inputArray = {1, 2, valueToEvaluate, 8, 4, 5, valueToEvaluate, 0, 9, 8, valueToEvaluate};
ArrayUtility<Integer> arrayUtility = new ArrayUtility<Integer>(inputArray);
// When
Integer actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
// Then
Assert.assertEquals(expected, actual);
}
@Test
public void longTest() {
// Given
Long valueToEvaluate = 7L;
Integer expected = 4;
Long[] inputArray = {1L, 2L, valueToEvaluate, 8L, 4L, 5L, valueToEvaluate, 0L, 9L, 8L, valueToEvaluate, valueToEvaluate};
ArrayUtility<Long> arrayUtility = new ArrayUtility<Long>(inputArray);
// When
Object actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
// Then
Assert.assertEquals(expected, actual);
}
@Test
public void stringTest() {
// Given
String valueToEvaluate = "a";
Integer expected = 2;
String[] inputArray = {"1", "2", valueToEvaluate, "8", "4", "5", valueToEvaluate, "0", "9", "8"};
ArrayUtility<String> arrayUtility = new ArrayUtility<String>(inputArray);
// When
Object actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
// Then
Assert.assertEquals(expected, actual);
}
@Test
public void objectTest() {
// Given
Object valueToEvaluate = new Object();
Integer expected = 1;
Object[] inputArray = {"1", "2", "8", "4", "5", "0", "9", "8", valueToEvaluate};
ArrayUtility<Object> arrayUtility = new ArrayUtility<Object>(inputArray);
// When
Object actual = arrayUtility.getNumberOfOccurrences(valueToEvaluate);
// Then
Assert.assertEquals(expected, actual);
}
}