Files
units/units_test.go
zeekay 9e9753716c test: pin the denomination constants
They are the whole of this package, and a factor-of-a-thousand typo in one of
them is otherwise invisible.
2026-08-21 00:19:34 -07:00

44 lines
1.1 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package units
import "testing"
// The constants are the whole of this package, so the test is the constants:
// a denomination that drifts by a factor of a thousand is a money bug, and a
// typo here is otherwise invisible.
func TestDenominations(t *testing.T) {
for _, c := range []struct {
name string
got uint64
want uint64
}{
{"NanoLux", NanoLux, 1},
{"MicroLux", MicroLux, 1_000},
{"MilliLux", MilliLux, 1_000_000},
{"Lux", Lux, 1_000_000_000},
{"KiloLux", KiloLux, 1_000_000_000_000},
{"MegaLux", MegaLux, 1_000_000_000_000_000},
{"Schmeckle", Schmeckle, 49_463},
{"Wei", Wei, 1},
{"GWei", GWei, 1_000_000_000},
{"Ether", Ether, 1_000_000_000_000_000_000},
{"Second", Second, 1},
{"Minute", Minute, 60},
{"Hour", Hour, 3_600},
{"Day", Day, 86_400},
{"Week", Week, 604_800},
{"KiB", KiB, 1 << 10},
{"MiB", MiB, 1 << 20},
{"GiB", GiB, 1 << 30},
} {
if c.got != c.want {
t.Errorf("%s = %d; want %d", c.name, c.got, c.want)
}
}
}