Skip to content

Commit 994791a

Browse files
committed
Added tests
1 parent 4a42f8a commit 994791a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/test/java/g3601_3700/s3677_count_binary_palindromic_numbers/SolutionTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,45 @@ void countBinaryPalindromes() {
1515
void countBinaryPalindromes2() {
1616
assertThat(new Solution().countBinaryPalindromes(9L), equalTo(6));
1717
}
18+
19+
@Test
20+
void countBinaryPalindromes3() {
21+
// Branch: n == 0 → returns 1 immediately
22+
assertThat(new Solution().countBinaryPalindromes(0), equalTo(1));
23+
}
24+
25+
@Test
26+
void countBinaryPalindromes4() {
27+
// n = 1 ("1") → palindrome
28+
// Expected palindromes: 1 (0) + 1 (1) = 2
29+
assertThat(new Solution().countBinaryPalindromes(1), equalTo(2));
30+
}
31+
32+
@Test
33+
void countBinaryPalindromes5() {
34+
// n = 6 ("110"), length = 3 (odd)
35+
// Palindromes up to 6: 0,1,3,5
36+
assertThat(new Solution().countBinaryPalindromes(6), equalTo(4));
37+
}
38+
39+
@Test
40+
void countBinaryPalindromes6() {
41+
// n = 9 ("1001"), palindrome itself
42+
// Palindromes up to 9: 0,1,3,5,7,9
43+
assertThat(new Solution().countBinaryPalindromes(9), equalTo(6));
44+
}
45+
46+
@Test
47+
void countBinaryPalindromes7() {
48+
// n = 10 ("1010") → next palindrome = 9 (smaller) → branch where palin <= n
49+
// Palindromes up to 10: 0,1,3,5,7,9
50+
assertThat(new Solution().countBinaryPalindromes(10), equalTo(6));
51+
}
52+
53+
@Test
54+
void countBinaryPalindromes8() {
55+
// 1023 = "1111111111"
56+
long n = (1L << 10) - 1;
57+
assertThat(new Solution().countBinaryPalindromes(n), equalTo(63));
58+
}
1859
}

0 commit comments

Comments
 (0)