@@ -26,17 +26,32 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
26
26
)
27
27
) {
28
28
@Test
29
- @Disabled(" Flaky test: https://github.com/UnitTestBot/UTBotJava/issues/131 (will be enabled in new strings PR)" )
30
29
fun testByteToString () {
31
- // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
32
- withSolverTimeoutInMillis(5000 ) {
33
- check(
34
- StringExamples ::byteToString,
35
- eq(2 ),
36
- { a, b, r -> a > b && r == a.toString() },
37
- { a, b, r -> a <= b && r == b.toString() },
38
- )
39
- }
30
+ check(
31
+ StringExamples ::byteToString,
32
+ eq(2 ),
33
+ { a, b, r -> a > b && r == a.toString() },
34
+ { a, b, r -> a <= b && r == b.toString() },
35
+ )
36
+ }
37
+
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
+ )
40
55
}
41
56
42
57
@Test
@@ -53,45 +68,91 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
53
68
54
69
@Test
55
70
fun testShortToString () {
56
- // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
57
- withSolverTimeoutInMillis(5000 ) {
58
- check(
59
- StringExamples ::shortToString,
60
- eq(2 ),
61
- { a, b, r -> a > b && r == a.toString() },
62
- { a, b, r -> a <= b && r == b.toString() },
63
- )
64
- }
71
+ check(
72
+ StringExamples ::shortToString,
73
+ ignoreExecutionsNumber,
74
+ { a, b, r -> a > b && r == a.toString() },
75
+ { a, b, r -> a <= b && r == b.toString() },
76
+ )
65
77
}
66
78
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
+ }
67
97
68
98
@Test
69
99
fun testIntToString () {
70
- // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
71
- withSolverTimeoutInMillis(5000 ) {
72
- check(
73
- StringExamples ::intToString,
74
- ignoreExecutionsNumber,
75
- { a, b, r -> a > b && r == a.toString() },
76
- { a, b, r -> a <= b && r == b.toString() },
77
- )
78
- }
100
+ check(
101
+ StringExamples ::intToString,
102
+ ignoreExecutionsNumber,
103
+ { a, b, r -> a > b && r == a.toString() },
104
+ { a, b, r -> a <= b && r == b.toString() },
105
+ )
79
106
}
80
107
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
+ }
81
126
82
127
@Test
83
128
fun testLongToString () {
84
- // TODO related to the https://github.com/UnitTestBot/UTBotJava/issues/131
85
- withSolverTimeoutInMillis(5000 ) {
86
- check(
87
- StringExamples ::longToString,
88
- ignoreExecutionsNumber,
89
- { a, b, r -> a > b && r == a.toString() },
90
- { a, b, r -> a <= b && r == b.toString() },
91
- )
92
- }
129
+ check(
130
+ StringExamples ::longToString,
131
+ ignoreExecutionsNumber,
132
+ { a, b, r -> a > b && r == a.toString() },
133
+ { a, b, r -> a <= b && r == b.toString() },
134
+ )
93
135
}
94
136
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
+
95
156
@Test
96
157
fun testStartsWithLiteral () {
97
158
check(
@@ -250,6 +311,15 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
250
311
)
251
312
}
252
313
314
+ @Test
315
+ fun testIsStringBuilderEmpty () {
316
+ check(
317
+ StringExamples ::isStringBuilderEmpty,
318
+ eq(2 ),
319
+ { stringBuilder, result -> result == stringBuilder.isEmpty() }
320
+ )
321
+ }
322
+
253
323
@Test
254
324
@Disabled(" Flaky on GitHub: https://github.com/UnitTestBot/UTBotJava/issues/1004" )
255
325
fun testIsValidUuid () {
@@ -332,7 +402,7 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
332
402
fun testSubstring () {
333
403
checkWithException(
334
404
StringExamples ::substring,
335
- between(5 .. 7 ),
405
+ between(5 .. 8 ),
336
406
{ s, _, r -> s == null && r.isException<NullPointerException >() },
337
407
{ s, i, r -> s != null && i < 0 || i > s.length && r.isException<StringIndexOutOfBoundsException >() },
338
408
{ s, i, r -> s != null && i in 0 .. s.length && r.getOrThrow() == s.substring(i) && s.substring(i) != " password" },
@@ -585,13 +655,14 @@ internal class StringExamplesTest : UtValueTestCaseChecker(
585
655
withPushingStateFromPathSelectorForConcrete {
586
656
check(
587
657
StringExamples ::equalsIgnoreCase,
588
- eq( 2 ) ,
658
+ ignoreExecutionsNumber ,
589
659
{ s, r -> " SUCCESS" .equals(s, ignoreCase = true ) && r == " success" },
590
660
{ s, r -> ! " SUCCESS" .equals(s, ignoreCase = true ) && r == " failure" },
591
661
)
592
662
}
593
663
}
594
664
665
+ // TODO: This test fails without concrete execution as it uses a symbolic variable
595
666
@Test
596
667
fun testListToString () {
597
668
check(
0 commit comments