@@ -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