Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public String eval(String str, Integer pos, Integer length) {
if (str == null || pos == null || length == null) {
return null;
}
if (pos == Integer.MIN_VALUE) {
return str;
}
if ((Math.abs(pos) > str.length())) {
return str;
}
Expand Down Expand Up @@ -64,6 +67,9 @@ public BinaryString eval(BinaryString str, Integer pos, Integer length) {
if (str == null || pos == null || length == null) {
return null;
}
if (pos == Integer.MIN_VALUE) {
return null;
}
if (Math.abs(pos) > str.getLength()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ public void test() {
Assert.assertEquals(sb.eval(BinaryString.fromString("Facebook"), -5).toString(), "ebook");
Assert.assertEquals(sb.eval(BinaryString.fromString("Facebook"), 5, 1).toString(), "b");
}

@Test
public void testIntegerMinValue() {
Substr sb = new Substr();

// Test Integer.MIN_VALUE for String version
Assert.assertEquals(sb.eval("hello", Integer.MIN_VALUE, 1), "hello");
Assert.assertEquals(sb.eval("hello", Integer.MIN_VALUE), "hello");

// Test Integer.MIN_VALUE for BinaryString version
Assert.assertNull(sb.eval(BinaryString.fromString("hello"), Integer.MIN_VALUE, 1));
Assert.assertNull(sb.eval(BinaryString.fromString("hello"), Integer.MIN_VALUE));
}
}