Skip to content

Commit bfbc69c

Browse files
committed
CR fixes + additional tests to check that silly mistakes have been fixed
1 parent c3478cd commit bfbc69c

File tree

6 files changed

+124
-17
lines changed

6 files changed

+124
-17
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/examples/strings/StringExamplesTest.kt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
3535
)
3636
}
3737

38+
@Test
39+
fun testByteToStringWithConstants() {
40+
val values: Array<Byte> = arrayOf(
41+
Byte.MIN_VALUE,
42+
(Byte.MIN_VALUE + 100).toByte(),
43+
0.toByte(),
44+
(Byte.MAX_VALUE - 100).toByte(),
45+
Byte.MAX_VALUE
46+
)
47+
48+
val expected = values.map { it.toString() }
49+
50+
check(
51+
StringExamples::byteToStringWithConstants,
52+
eq(1),
53+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
54+
)
55+
}
56+
3857
@Test
3958
fun testReplace() {
4059
check(
@@ -57,6 +76,24 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
5776
)
5877
}
5978

79+
@Test
80+
fun testShortToStringWithConstants() {
81+
val values: Array<Short> = arrayOf(
82+
Short.MIN_VALUE,
83+
(Short.MIN_VALUE + 100).toShort(),
84+
0.toShort(),
85+
(Short.MAX_VALUE - 100).toShort(),
86+
Short.MAX_VALUE
87+
)
88+
89+
val expected = values.map { it.toString() }
90+
91+
check(
92+
StringExamples::shortToStringWithConstants,
93+
eq(1),
94+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
95+
)
96+
}
6097

6198
@Test
6299
fun testIntToString() {
@@ -68,6 +105,24 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
68105
)
69106
}
70107

108+
@Test
109+
fun testIntToStringWithConstants() {
110+
val values: Array<Int> = arrayOf(
111+
Integer.MIN_VALUE,
112+
Integer.MIN_VALUE + 100,
113+
0,
114+
Integer.MAX_VALUE - 100,
115+
Integer.MAX_VALUE
116+
)
117+
118+
val expected = values.map { it.toString() }
119+
120+
check(
121+
StringExamples::intToStringWithConstants,
122+
eq(1),
123+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
124+
)
125+
}
71126

72127
@Test
73128
fun testLongToString() {
@@ -79,6 +134,25 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
79134
)
80135
}
81136

137+
@Test
138+
fun testLongToStringWithConstants() {
139+
val values: Array<Long> = arrayOf(
140+
Long.MIN_VALUE,
141+
Long.MIN_VALUE + 100L,
142+
0L,
143+
Long.MAX_VALUE - 100L,
144+
Long.MAX_VALUE
145+
)
146+
147+
val expected = values.map { it.toString() }
148+
149+
check(
150+
StringExamples::longToStringWithConstants,
151+
eq(1),
152+
{ r -> r != null && r.indices.all { r[it] == expected[it] } }
153+
)
154+
}
155+
82156
@Test
83157
fun testStartsWithLiteral() {
84158
check(

utbot-framework/src/main/java/org/utbot/engine/overrides/Byte.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static String toString(byte b) {
5858

5959
// assumes are placed here to limit search space of solver
6060
// and reduce time of solving queries with bv2int expressions
61-
assume(b < 128);
61+
assume(b <= 127);
6262
assume(b > -128);
6363
assume(b != 0);
6464

utbot-framework/src/main/java/org/utbot/engine/overrides/Integer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ public static String toString(int i) {
8080
return "0";
8181
}
8282

83-
assume(i <= 0x7FFFFFFF); // java.lang.Integer.MAX_VALUE
84-
assume(i > 0x80000000); // java.lang.Integer.MIN_VALUE
85-
assume(i != 0);
86-
8783
// isNegative = i < 0
8884
boolean isNegative = less(i, 0);
8985
String prefix = ite(isNegative, "-", "");
@@ -93,7 +89,7 @@ public static String toString(int i) {
9389
int offset = 0;
9490
while (value > 0) {
9591
reversed[offset] = (char) ('0' + (value % 10));
96-
value /= value;
92+
value /= 10;
9793
offset++;
9894
}
9995

utbot-framework/src/main/java/org/utbot/engine/overrides/Long.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,6 @@ public static String toString(long l) {
8080
return "0";
8181
}
8282

83-
// assumes are placed here to limit search space of solver
84-
// and reduce time of solving queries with bv2int expressions
85-
assume(l <= 0x7FFFFFFFFFFFFFFFL); // java.lang.Long.MAX_VALUE
86-
assume(l > 0x8000000000000000L); // java.lang.Long.MIN_VALUE
87-
assume(l != 0);
88-
8983
// isNegative = i < 0
9084
boolean isNegative = less(l, 0);
9185
String prefix = ite(isNegative, "-", "");
@@ -95,7 +89,7 @@ public static String toString(long l) {
9589
int offset = 0;
9690
while (value > 0) {
9791
reversed[offset] = (char) ('0' + (value % 10));
98-
value /= value;
92+
value /= 10;
9993
offset++;
10094
}
10195

utbot-framework/src/main/java/org/utbot/engine/overrides/Short.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ public static java.lang.Short parseShort(String s, int radix) {
4646

4747
@SuppressWarnings("ConstantConditions")
4848
public static String toString(short s) {
49-
if (s == -32768)
49+
if (s == -32768) {
5050
return "-32768";
51-
if (s == 0)
51+
}
52+
53+
if (s == 0) {
5254
return "0";
55+
}
5356

5457
// assumes are placed here to limit search space of solver
5558
// and reduce time of solving queries with bv2int expressions
56-
assume(s < 32768);
59+
assume(s <= 32767);
5760
assume(s > -32768);
5861
assume(s != 0);
5962

@@ -66,7 +69,7 @@ public static String toString(short s) {
6669
int offset = 0;
6770
while (value > 0) {
6871
reversed[offset] = (char) ('0' + (value % 10));
69-
value /= value;
72+
value /= 10;
7073
offset++;
7174
}
7275

utbot-sample/src/main/java/org/utbot/examples/strings/StringExamples.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ public String intToString(int a, int b) {
4646
}
4747
}
4848

49+
public String[] intToStringWithConstants() {
50+
return new String[]{
51+
Integer.toString(Integer.MIN_VALUE),
52+
Integer.toString(Integer.MIN_VALUE + 100),
53+
Integer.toString(0),
54+
Integer.toString(Integer.MAX_VALUE - 100),
55+
Integer.toString(Integer.MAX_VALUE)
56+
};
57+
}
58+
4959
public String longToString(long a, long b) {
5060
if (a > b) {
5161
return Long.toString(a);
@@ -54,6 +64,16 @@ public String longToString(long a, long b) {
5464
}
5565
}
5666

67+
public String[] longToStringWithConstants() {
68+
return new String[]{
69+
Long.toString(Long.MIN_VALUE),
70+
Long.toString(Long.MIN_VALUE + 100L),
71+
Long.toString(0),
72+
Long.toString(Long.MAX_VALUE - 100L),
73+
Long.toString(Long.MAX_VALUE)
74+
};
75+
}
76+
5777
public String startsWithLiteral(String str) {
5878
if (str.startsWith("1234567890")) {
5979
str = str.replace("3", "A");
@@ -76,6 +96,16 @@ public String byteToString(byte a, byte b) {
7696
}
7797
}
7898

99+
public String[] byteToStringWithConstants() {
100+
return new String[]{
101+
Byte.toString(Byte.MIN_VALUE),
102+
Byte.toString((byte) (Byte.MIN_VALUE + 100)),
103+
Byte.toString((byte) 0),
104+
Byte.toString((byte) (Byte.MAX_VALUE - 100)),
105+
Byte.toString(Byte.MAX_VALUE)
106+
};
107+
}
108+
79109
public String replace(String a, String b) {
80110
return a.replace("abc", b);
81111
}
@@ -96,6 +126,16 @@ public String shortToString(short a, short b) {
96126
}
97127
}
98128

129+
public String[] shortToStringWithConstants() {
130+
return new String[]{
131+
Short.toString(Short.MIN_VALUE),
132+
Short.toString((short) (Short.MIN_VALUE + 100)),
133+
Short.toString((short) 0),
134+
Short.toString((short) (Short.MAX_VALUE - 100)),
135+
Short.toString(Short.MAX_VALUE)
136+
};
137+
}
138+
99139
public String booleanToString(boolean a, boolean b) {
100140
if (a ^ b) {
101141
return Boolean.toString(a ^ b);

0 commit comments

Comments
 (0)