-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
binary16: use text/template for test case generation
- Loading branch information
Showing
3 changed files
with
121 additions
and
107 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Code generated by go run gen.go; DO NOT EDIT. | ||
|
||
package binary16 | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
) | ||
|
||
func TestNewFromBitsNormalized(t *testing.T) { | ||
for _, g := range goldenNormalized { | ||
f := NewFromBits(g.bits) | ||
got, _ := f.Float64() | ||
wantBits := math.Float64bits(g.want) | ||
gotBits := math.Float64bits(got) | ||
if wantBits != gotBits { | ||
t.Errorf("0x%04X: number mismatch; expected 0x%016X (%v), got 0x%016X (%v)", g.bits, wantBits, g.want, gotBits, got) | ||
} | ||
} | ||
} | ||
|
||
func TestNewFromBitsDenormalized(t *testing.T) { | ||
for _, g := range goldenDenormalized { | ||
f := NewFromBits(g.bits) | ||
got, _ := f.Float64() | ||
wantBits := math.Float64bits(g.want) | ||
gotBits := math.Float64bits(got) | ||
if wantBits != gotBits { | ||
t.Errorf("0x%04X: number mismatch; expected 0x%016X (%v), got 0x%016X (%v)", g.bits, wantBits, g.want, gotBits, got) | ||
} | ||
} | ||
} | ||
|
||
func TestNewFromFloat32Normalized(t *testing.T) { | ||
for _, g := range goldenNormalized { | ||
in := float32(g.want) | ||
f, acc := NewFromFloat32(in) | ||
_ = acc | ||
got := f.Bits() | ||
if g.bits != got { | ||
t.Errorf("%v: bits mismatch; expected 0x%04X, got 0x%04X", in, g.bits, got) | ||
} | ||
} | ||
} | ||
|
||
func TestNewFromFloat64Normalized(t *testing.T) { | ||
for _, g := range goldenNormalized { | ||
f, acc := NewFromFloat64(g.want) | ||
_ = acc | ||
got := f.Bits() | ||
if g.bits != got { | ||
t.Errorf("%v: bits mismatch; expected 0x%04X, got 0x%04X", g.want, g.bits, got) | ||
} | ||
} | ||
} | ||
|
||
func TestNewFromFloat32Denormalized(t *testing.T) { | ||
for _, g := range goldenDenormalized { | ||
f, acc := NewFromFloat32(float32(g.want)) | ||
_ = acc | ||
got := f.Bits() | ||
if g.bits != got { | ||
t.Errorf("%v: bits mismatch; expected 0x%04X, got 0x%04X", g.want, g.bits, got) | ||
} | ||
} | ||
} | ||
|
||
func TestNewFromFloat64Denormalized(t *testing.T) { | ||
for _, g := range goldenDenormalized { | ||
f, acc := NewFromFloat64(g.want) | ||
_ = acc | ||
got := f.Bits() | ||
if g.bits != got { | ||
t.Errorf("%v: bits mismatch; expected 0x%04X, got 0x%04X", g.want, g.bits, got) | ||
} | ||
} | ||
} | ||
|
||
var goldenNormalized = []struct { | ||
bits uint16 | ||
want float64 | ||
}{ | ||
// Normalized values. | ||
{{- range .normalized }} | ||
{{ . }}, | ||
{{- end }} | ||
} | ||
|
||
var goldenDenormalized = []struct { | ||
bits uint16 | ||
want float64 | ||
}{ | ||
// Denormalized values. | ||
{{- range .denormalized }} | ||
{{ . }}, | ||
{{- end }} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters