File: float16_test.go

package info (click to toggle)
golang-github-aws-smithy-go 1.20.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,116 kB
  • sloc: java: 19,678; xml: 166; sh: 131; makefile: 70
file content (41 lines) | stat: -rw-r--r-- 767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cbor

import (
	"testing"
)

func TestFloat16To32(t *testing.T) {
	for name, c := range map[string]struct {
		In     uint16
		Expect uint32
	}{
		"+infinity": {
			0b0_11111_0000000000,
			0b0_11111111_00000000000000000000000,
		},
		"-infinity": {
			0b1_11111_0000000000,
			0b1_11111111_00000000000000000000000,
		},
		"NaN": {
			0b0_11111_0101010101,
			0b0_11111111_01010101010000000000000,
		},
		"absolute zero": {0, 0},
		"subnormal": {
			0b0_00000_0001010000,
			0b0_01101101_01000000000000000000000,
		},
		"normal": {
			0b0_00001_0001010000,
			0b0_0001110001_00010100000000000000000,
		},
	} {
		t.Run(name, func(t *testing.T) {
			if actual := float16to32(c.In); c.Expect != actual {
				t.Errorf("%x != %x", c.Expect, actual)
			}
		})
	}

}