1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

math.big: add test cases for is_power_of_2 (#18910)

This commit is contained in:
phoebe 2023-07-20 01:34:31 +02:00 committed by GitHub
parent d66b097ddc
commit 6fef2c2ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,6 +102,24 @@ const integer_from_radix_test_data = [
] ]
// vfmt on // vfmt on
// is_*
struct IsXTest {
value TestInteger
expected bool
}
// vfmt off
const is_power_of_2_test_data = [
IsXTest{ u32(0b110000000000), false },
IsXTest{ "537502395172353242345", false },
IsXTest{ "590295810358705700000", false },
IsXTest{ "1125899906842624", true },
IsXTest{ "590295810358705651712", true },
IsXTest{ "4611686018427388002", false },
IsXTest{ "31195165372897259196222538898096203590151924108450147950531565441852619837316692843188389598728651769482088968838700984268947453885587967878549286444999755742573423371025356539077075265986419171772426279084559025861175301940492273427120221755816136975739916983004778387946699939545354293487098252428954036286183995782377175227121587657233553706589448547148066273280603243167958729707736664649187444136702017299877489729451997277875868782399735511520086969969766278182145454186690598629675562422923132555707758646587702550600894625696538109646366308973392363200122154242784576162149305816215109893613161331026672647000825615987247035266514313689413563779184515427920269935280569035788081552413007563772309295149800172031645681720569680154349893907395864528243629654386620034655445226295834594630792819545156798270599481573436039129275439653984521135652249263653985326577886990615665734998585216581730937090703518997669223802429711292740491797911117308280939507973715877108492303860661291987529284719391551256912380499409630332506454532263266457209921483705507359152839264852808182519011100934922492651373859423833024010283468753147686188675294998119637462200763443029190704825719342806119404339670408160210011918981038977425180213726646978883378058838510330816291941879581568740273684084511318422175006728346276489384220596694727036836687670632486602655240593463885077059375085482211864761344849868123074687509143827139683659102930877963676911995751113159944160296419825178911962487549670296207457410515598040046860567719116506974858703739531721991704589155513182996455827177472", true },
]
// vfmt on
struct AddTest { struct AddTest {
augend TestInteger augend TestInteger
addend TestInteger addend TestInteger
@ -490,6 +508,12 @@ fn test_bytes() {
assert sign == 1 assert sign == 1
} }
fn test_is_power_of_2() {
for t in is_power_of_2_test_data {
assert t.value.parse().is_power_of_2() == t.expected
}
}
fn test_addition() { fn test_addition() {
for t in add_test_data { for t in add_test_data {
assert t.augend.parse() + t.addend.parse() == t.sum.parse() assert t.augend.parse() + t.addend.parse() == t.sum.parse()