diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-03-03 14:22:43 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-03-03 14:22:43 -0500 |
| commit | 0a0b9b8cc9cdc0ffe1819de0266dd1e3c3eb564f (patch) | |
| tree | ead2723b26a2dcb1d1db80efc01390579056d4fc /style/fixed_test.go | |
| parent | 8858a54b5ddb3a2d8a42ecb1a837c02800bc934f (diff) | |
| download | gui-0a0b9b8cc9cdc0ffe1819de0266dd1e3c3eb564f.zip | |
style: unit conversion
Implemented the golang.org/x/exp/shiny/unit.Converter interface on
style.Style.
Diffstat (limited to 'style/fixed_test.go')
| -rw-r--r-- | style/fixed_test.go | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/style/fixed_test.go b/style/fixed_test.go new file mode 100644 index 0000000..5cae4bf --- /dev/null +++ b/style/fixed_test.go @@ -0,0 +1,74 @@ +package style + +import ( + "testing" + + "golang.org/x/image/math/fixed" +) + +func TestFixed26ToFloat(t *testing.T) { + t.Parallel() + + var ( + in fixed.Int26_6 + out, want float64 + ) + + in = 0 + out = fixed26ToFloat(in) + want = 0 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.I(123) + out = fixed26ToFloat(in) + want = 123 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.I(-123) + out = fixed26ToFloat(in) + want = -123 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.Int26_6(1<<6 + 1<<4) + out = fixed26ToFloat(in) + want = 1.25 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } +} + +func TestFloatToFixed26(t *testing.T) { + t.Parallel() + + var ( + in float64 + out, want fixed.Int26_6 + ) + + in = 0 + out = floatToFixed26(in) + want = 0 + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } + + in = 1.25 + out = floatToFixed26(in) + want = fixed.Int26_6(1<<6 + 1<<4) + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } + + in = -1.25 + out = floatToFixed26(in) + want = -fixed.Int26_6(1<<6 + 1<<4) + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } +} |