Skip to content

Commit 6fef2c2

Browse files
author
phoebe
authored
math.big: add test cases for is_power_of_2 (#18910)
1 parent d66b097 commit 6fef2c2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

vlib/math/big/big_test.v

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ const integer_from_radix_test_data = [
102102
]
103103
// vfmt on
104104

105+
// is_*
106+
struct IsXTest {
107+
value TestInteger
108+
expected bool
109+
}
110+
111+
// vfmt off
112+
const is_power_of_2_test_data = [
113+
IsXTest{ u32(0b110000000000), false },
114+
IsXTest{ "537502395172353242345", false },
115+
IsXTest{ "590295810358705700000", false },
116+
IsXTest{ "1125899906842624", true },
117+
IsXTest{ "590295810358705651712", true },
118+
IsXTest{ "4611686018427388002", false },
119+
IsXTest{ "31195165372897259196222538898096203590151924108450147950531565441852619837316692843188389598728651769482088968838700984268947453885587967878549286444999755742573423371025356539077075265986419171772426279084559025861175301940492273427120221755816136975739916983004778387946699939545354293487098252428954036286183995782377175227121587657233553706589448547148066273280603243167958729707736664649187444136702017299877489729451997277875868782399735511520086969969766278182145454186690598629675562422923132555707758646587702550600894625696538109646366308973392363200122154242784576162149305816215109893613161331026672647000825615987247035266514313689413563779184515427920269935280569035788081552413007563772309295149800172031645681720569680154349893907395864528243629654386620034655445226295834594630792819545156798270599481573436039129275439653984521135652249263653985326577886990615665734998585216581730937090703518997669223802429711292740491797911117308280939507973715877108492303860661291987529284719391551256912380499409630332506454532263266457209921483705507359152839264852808182519011100934922492651373859423833024010283468753147686188675294998119637462200763443029190704825719342806119404339670408160210011918981038977425180213726646978883378058838510330816291941879581568740273684084511318422175006728346276489384220596694727036836687670632486602655240593463885077059375085482211864761344849868123074687509143827139683659102930877963676911995751113159944160296419825178911962487549670296207457410515598040046860567719116506974858703739531721991704589155513182996455827177472", true },
120+
]
121+
// vfmt on
122+
105123
struct AddTest {
106124
augend TestInteger
107125
addend TestInteger
@@ -490,6 +508,12 @@ fn test_bytes() {
490508
assert sign == 1
491509
}
492510

511+
fn test_is_power_of_2() {
512+
for t in is_power_of_2_test_data {
513+
assert t.value.parse().is_power_of_2() == t.expected
514+
}
515+
}
516+
493517
fn test_addition() {
494518
for t in add_test_data {
495519
assert t.augend.parse() + t.addend.parse() == t.sum.parse()

0 commit comments

Comments
 (0)