-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString2LongTest.java
More file actions
55 lines (45 loc) · 1.63 KB
/
Copy pathString2LongTest.java
File metadata and controls
55 lines (45 loc) · 1.63 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
package main;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.Test;
public class String2LongTest {
String2Long s2i = new String2Long();
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
//Valid test cases
public void testStringToLong() {
assertEquals(0, s2i.stringToLong("00")); //zero
assertEquals(500, s2i.stringToLong("500")); //no sign number string
assertEquals(500, s2i.stringToLong("+500")); //+ sign number string
assertEquals(-500, s2i.stringToLong("-500")); //- sign number string
//huge integer
assertEquals(Integer.MAX_VALUE, s2i.stringToLong(Integer.toString(Integer.MAX_VALUE)));
//small integer
assertEquals(Integer.MIN_VALUE, s2i.stringToLong(Integer.toString(Integer.MIN_VALUE)));
//huge long
assertEquals(Long.MAX_VALUE, s2i.stringToLong(Long.toString(Long.MAX_VALUE)));
//small long
assertEquals(Long.MIN_VALUE, s2i.stringToLong(Long.toString(Long.MIN_VALUE)));
}
@Test
//IllegalArgument cases
public void testStringToIntIllegalArgument() {
exception.expect(IllegalArgumentException.class);
s2i.stringToLong(""); //empty string
s2i.stringToLong(null); //null string
}
@Test
//NumberFormatException cases
public void testStringToIntNumberFormatException() {
exception.expect(NumberFormatException.class);
s2i.stringToLong("e21");
s2i.stringToLong("1.666");
s2i.stringToLong("9zzaww");
s2i.stringToLong(" ");
assertEquals(500, s2i.stringToLong(" 500"));
s2i.stringToLong(Long.toString(Long.MAX_VALUE) + "11");
s2i.stringToLong(Long.toString(Long.MIN_VALUE) + "11");
}
}