Skip to content

Commit 3778cee

Browse files
Add test for String.hashCode
1 parent 630100f commit 3778cee

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Test {
2+
3+
public static int check(String s, int nondet) {
4+
if(s == null)
5+
return -1;
6+
7+
if(nondet == 0) {
8+
// This is always true
9+
assert "foo".hashCode() == 101574;
10+
} else if(nondet == 1) {
11+
// This is always false
12+
assert "foo".hashCode() != 101574;
13+
} else if(nondet == 2) {
14+
// This is sometimes false
15+
assert !s.startsWith("foo") && s.hashCode() == 101574;
16+
} else if(nondet == 3) {
17+
// This is always true
18+
assert s.hashCode() == 101574 || !(s.startsWith("foo") && s.length() == 3);
19+
} else {
20+
// This is always false
21+
assert "bar".hashCode() == 101574;
22+
}
23+
24+
return s.hashCode();
25+
}
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
Test.class
3+
--max-nondet-string-length 1000 --function Test.check --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --unwind 10
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
assertion at file Test.java line 8 function .*: SUCCESS
7+
assertion at file Test.java line 11 function .*: FAILURE
8+
assertion at file Test.java line 14 function .*: FAILURE
9+
assertion at file Test.java line 17 function .*: SUCCESS
10+
assertion at file Test.java line 20 function .*: FAILURE
11+

0 commit comments

Comments
 (0)