1313// limitations under the License.
1414
1515///|
16- test "overflow" {
16+ test "Int64 overflow" {
1717 inspect (0x8000000000000000L , content = "-9223372036854775808" )
1818 inspect (- 0x8000000000000000L , content = "-9223372036854775808" )
1919 inspect (0x7fffffffffffffffL , content = "9223372036854775807" )
2020 inspect (- 0x7fffffffffffffffL , content = "-9223372036854775807" )
2121}
2222
2323///|
24- test "from int " {
24+ test "Int64::from_int " {
2525 inspect (@int64 .from_int (1256 ), content = "1256" )
2626}
2727
@@ -32,148 +32,93 @@ test "Int64::min_value" {
3232}
3333
3434///|
35- test "shift" {
35+ test "Int64:: shift" {
3636 inspect (1L << 2 , content = "4" )
3737 inspect (4L >> 2 , content = "1" )
3838 inspect (- 2L >> 2 , content = "-1" )
3939 inspect (2L >> 2 , content = "0" )
4040}
4141
4242///|
43- test "grouped test for boundary cases" {
44- // Test for the smallest UInt64 value
45- inspect (UInt64 ::ctz (0UL ), content = "64" )
46-
47- // Test for the largest UInt64 value
48- inspect (UInt64 ::ctz (0xFFFFFFFFFFFFFFFFUL ), content = "0" )
49-
50- // Test for a value with a single bit set
51- inspect (UInt64 ::ctz (1UL ), content = "0" )
52-
53- // Test for a value with the most significant bit set
54- inspect (UInt64 ::ctz (0x8000000000000000UL ), content = "63" )
55- }
56-
57- ///|
58- test "grouped test for random cases" {
59- // Random cases to test various bit patterns
60- inspect (UInt64 ::ctz (0x0000000000000001UL ), content = "0" )
61- inspect (UInt64 ::ctz (0x0000000000000002UL ), content = "1" )
62- inspect (UInt64 ::ctz (0x0000000000000004UL ), content = "2" )
63- inspect (UInt64 ::ctz (0x0000000000000008UL ), content = "3" )
64- inspect (UInt64 ::ctz (0x0000000000000010UL ), content = "4" )
65- inspect (UInt64 ::ctz (0x0000000000000020UL ), content = "5" )
66- inspect (UInt64 ::ctz (0x0000000000000040UL ), content = "6" )
67- inspect (UInt64 ::ctz (0x0000000000000080UL ), content = "7" )
68- inspect (UInt64 ::ctz (0x0000000000000100UL ), content = "8" )
69- inspect (UInt64 ::ctz (0x0000000000000200UL ), content = "9" )
70- inspect (UInt64 ::ctz (0x0000000000000400UL ), content = "10" )
71- inspect (UInt64 ::ctz (0x0000000000000800UL ), content = "11" )
72- inspect (UInt64 ::ctz (0x0000000000001000UL ), content = "12" )
73- inspect (UInt64 ::ctz (0x0000000000002000UL ), content = "13" )
74- inspect (UInt64 ::ctz (0x0000000000004000UL ), content = "14" )
75- inspect (UInt64 ::ctz (0x0000000000008000UL ), content = "15" )
76- inspect (UInt64 ::ctz (0x0000000000010000UL ), content = "16" )
77- inspect (UInt64 ::ctz (0x0000000000020000UL ), content = "17" )
78- inspect (UInt64 ::ctz (0x0000000000040000UL ), content = "18" )
79- inspect (UInt64 ::ctz (0x0000000000080000UL ), content = "19" )
80- inspect (UInt64 ::ctz (0x0000000000100000UL ), content = "20" )
81- inspect (UInt64 ::ctz (0x0000000000200000UL ), content = "21" )
82- inspect (UInt64 ::ctz (0x0000000000400000UL ), content = "22" )
83- inspect (UInt64 ::ctz (0x0000000000800000UL ), content = "23" )
84- inspect (UInt64 ::ctz (0x0000000001000000UL ), content = "24" )
85- inspect (UInt64 ::ctz (0x0000000002000000UL ), content = "25" )
86- inspect (UInt64 ::ctz (0x0000000004000000UL ), content = "26" )
87- inspect (UInt64 ::ctz (0x0000000008000000UL ), content = "27" )
88- inspect (UInt64 ::ctz (0x0000000010000000UL ), content = "28" )
89- inspect (UInt64 ::ctz (0x0000000020000000UL ), content = "29" )
90- inspect (UInt64 ::ctz (0x0000000040000000UL ), content = "30" )
91- inspect (UInt64 ::ctz (0x0000000080000000UL ), content = "31" )
92- inspect (UInt64 ::ctz (0x0000000100000000UL ), content = "32" )
93- inspect (UInt64 ::ctz (0x0000000200000000UL ), content = "33" )
94- inspect (UInt64 ::ctz (0x0000000400000000UL ), content = "34" )
95- inspect (UInt64 ::ctz (0x0000000800000000UL ), content = "35" )
96- inspect (UInt64 ::ctz (0x0000001000000000UL ), content = "36" )
97- inspect (UInt64 ::ctz (0x0000002000000000UL ), content = "37" )
98- inspect (UInt64 ::ctz (0x0000004000000000UL ), content = "38" )
99- inspect (UInt64 ::ctz (0x0000008000000000UL ), content = "39" )
100- inspect (UInt64 ::ctz (0x0000010000000000UL ), content = "40" )
101- inspect (UInt64 ::ctz (0x0000020000000000UL ), content = "41" )
102- inspect (UInt64 ::ctz (0x0000040000000000UL ), content = "42" )
103- inspect (UInt64 ::ctz (0x0000080000000000UL ), content = "43" )
104- inspect (UInt64 ::ctz (0x0000100000000000UL ), content = "44" )
105- inspect (UInt64 ::ctz (0x0000200000000000UL ), content = "45" )
106- inspect (UInt64 ::ctz (0x0000400000000000UL ), content = "46" )
107- inspect (UInt64 ::ctz (0x0000800000000000UL ), content = "47" )
108- inspect (UInt64 ::ctz (0x0001000000000000UL ), content = "48" )
109- inspect (UInt64 ::ctz (0x0002000000000000UL ), content = "49" )
110- inspect (UInt64 ::ctz (0x0004000000000000UL ), content = "50" )
111- inspect (UInt64 ::ctz (0x0008000000000000UL ), content = "51" )
112- inspect (UInt64 ::ctz (0x0010000000000000UL ), content = "52" )
113- inspect (UInt64 ::ctz (0x0020000000000000UL ), content = "53" )
114- inspect (UInt64 ::ctz (0x0040000000000000UL ), content = "54" )
115- inspect (UInt64 ::ctz (0x0080000000000000UL ), content = "55" )
116- inspect (UInt64 ::ctz (0x0100000000000000UL ), content = "56" )
117- inspect (UInt64 ::ctz (0x0200000000000000UL ), content = "57" )
118- inspect (UInt64 ::ctz (0x0400000000000000UL ), content = "58" )
119- inspect (UInt64 ::ctz (0x0800000000000000UL ), content = "59" )
120- inspect (UInt64 ::ctz (0x1000000000000000UL ), content = "60" )
121- inspect (UInt64 ::ctz (0x2000000000000000UL ), content = "61" )
122- inspect (UInt64 ::ctz (0x4000000000000000UL ), content = "62" )
123- inspect (UInt64 ::ctz (0x8000000000000000UL ), content = "63" )
124- }
125-
126- ///|
127- test "grouped test for boundary cases: clz" {
128- inspect (UInt64 ::clz (0UL ), content = "64" )
129- inspect (UInt64 ::clz (1UL ), content = "63" )
130- inspect (UInt64 ::clz (0x8000000000000000UL ), content = "0" )
131- inspect (UInt64 ::clz (0x7FFFFFFFFFFFFFFFUL ), content = "1" )
43+ test "Int64::ctz boundary cases" {
44+ inspect (Int64 ::ctz (0L ), content = "64" )
45+ inspect (Int64 ::ctz (1L ), content = "0" )
46+ inspect (Int64 ::ctz (- 1L ), content = "0" )
47+ inspect (Int64 ::ctz (@int64 .min_value), content = "63" )
48+ inspect (Int64 ::ctz (@int64 .max_value), content = "0" )
13249}
13350
13451///|
135- test "grouped test for random cases: clz" {
136- inspect (UInt64 ::clz (0x123456789ABCDEF0UL ), content = "3" )
137- inspect (UInt64 ::clz (0xABCDEF0123456789UL ), content = "0" )
138- inspect (UInt64 ::clz (0x00000000FFFFFFFFUL ), content = "32" )
139- inspect (UInt64 ::clz (0x0000000000000001UL ), content = "63" )
140- inspect (UInt64 ::clz (0x000000000000000FUL ), content = "60" )
141- inspect (UInt64 ::clz (0x00000000000000FFUL ), content = "56" )
52+ test "Int64::ctz mixed cases" {
53+ // Cover positive and negative values with various trailing zero counts.
54+ let cases = [
55+ (2L , 1 ),
56+ (- 2L , 1 ),
57+ (4L , 2 ),
58+ (- 4L , 2 ),
59+ (0x0000000000000080L , 7 ),
60+ (0x0000000000008000L , 15 ),
61+ (0x0000000001000000L , 24 ),
62+ (0x0000001000000000L , 36 ),
63+ (0x0000100000000000L , 44 ),
64+ (0x0001000000000000L , 48 ),
65+ (0x0040000000000000L , 54 ),
66+ (0x4000000000000000L , 62 ),
67+ ]
68+ for case in cases {
69+ let (value , expected ) = case
70+ assert_eq (Int64 ::ctz (value ), expected )
71+ }
14272}
14373
14474///|
145- test "grouped test for edge cases with specific patterns" {
146- inspect (UInt64 ::clz (0x0000000000000000UL ), content = "64" )
147- inspect (UInt64 ::clz (0xFFFFFFFFFFFFFFFFUL ), content = "0" )
148- inspect (UInt64 ::clz (0x0000000000000001UL ), content = "63" )
149- inspect (UInt64 ::clz (0x8000000000000000UL ), content = "0" )
75+ test "Int64::clz boundary cases" {
76+ inspect (Int64 ::clz (0L ), content = "64" )
77+ inspect (Int64 ::clz (1L ), content = "63" )
78+ inspect (Int64 ::clz (@int64 .max_value), content = "1" )
79+ inspect (Int64 ::clz (@int64 .min_value), content = "0" )
80+ inspect (Int64 ::clz (- 1L ), content = "0" )
15081}
15182
15283///|
153- test "grouped test for basic functionality" {
154- inspect (UInt64 ::popcnt (0UL ), content = "0" )
155- inspect (UInt64 ::popcnt (1UL ), content = "1" )
156- inspect (UInt64 ::popcnt (2UL ), content = "1" )
157- inspect (UInt64 ::popcnt (3UL ), content = "2" )
84+ test "Int64::clz mixed cases" {
85+ let cases = [
86+ (0x123456789ABCDEF0L , 3 ),
87+ (0x00000000FFFFFFFFL , 32 ),
88+ (0x0000000000000001L , 63 ),
89+ (0x000000000000000FL , 60 ),
90+ (0x00000000000000FFL , 56 ),
91+ (- 0x543210FEDCBA9877L , 0 ),
92+ ]
93+ for case in cases {
94+ let (value , expected ) = case
95+ assert_eq (Int64 ::clz (value ), expected )
96+ }
15897}
15998
16099///|
161- test "grouped test for edge cases" {
162- inspect (UInt64 ::popcnt (0xFFFFFFFFFFFFFFFFUL ), content = "64" )
163- inspect (UInt64 ::popcnt (0x8000000000000000UL ), content = "1" )
164- inspect (UInt64 ::popcnt (0x7FFFFFFFFFFFFFFFUL ), content = "63" )
100+ test "Int64::popcnt boundary cases" {
101+ inspect (Int64 ::popcnt (0L ), content = "0" )
102+ inspect (Int64 ::popcnt (1L ), content = "1" )
103+ inspect (Int64 ::popcnt (- 1L ), content = "64" )
104+ inspect (Int64 ::popcnt (@int64 .min_value), content = "1" )
105+ inspect (Int64 ::popcnt (@int64 .max_value), content = "63" )
165106}
166107
167108///|
168- test "grouped test for random cases: popcnt" {
169- inspect (UInt64 ::popcnt (0x123456789ABCDEF0UL ), content = "32" )
170- inspect (UInt64 ::popcnt (0xABCDEF0123456789UL ), content = "32" )
171- inspect (UInt64 ::popcnt (0x5555555555555555UL ), content = "32" )
172- inspect (UInt64 ::popcnt (0xAAAAAAAAAAAAAAAAUL ), content = "32" )
173- // 1101111010101101101111101110111111011110101011011011111011101111
174- inspect (UInt64 ::popcnt (0xDEADBEEFDEADBEEFUL ), content = "48" )
175- // 1011111011101111110111101010110110111110111011111101111010101101
176- inspect (UInt64 ::popcnt (0xBEEFDEADBEEFDEADUL ), content = "48" )
109+ test "Int64::popcnt mixed cases" {
110+ let cases = [
111+ (0x123456789ABCDEF0L , 32 ),
112+ (0x0F0F0F0F0F0F0F0FL , 32 ),
113+ (0x5555555555555555L , 32 ),
114+ (- 2L , 63 ),
115+ (- 4L , 62 ),
116+ (- 0x4000000000000000L , 2 ),
117+ ]
118+ for case in cases {
119+ let (value , expected ) = case
120+ assert_eq (Int64 ::popcnt (value ), expected )
121+ }
177122}
178123
179124///|
0 commit comments