|
| 1 | +package float16 |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestTypesExtra(t *testing.T) { |
| 8 | + // Test Error method |
| 9 | + err := &Float16Error{Op: "test", Msg: "test error", Value: 1.0} |
| 10 | + if err.Error() != "float16.test: test error (value: 1)" { |
| 11 | + t.Errorf("Error method: expected 'float16.test: test error (value: 1)', got '%s'", err.Error()) |
| 12 | + } |
| 13 | + err = &Float16Error{Op: "test", Msg: "test error"} |
| 14 | + if err.Error() != "float16.test: test error" { |
| 15 | + t.Errorf("Error method: expected 'float16.test: test error', got '%s'", err.Error()) |
| 16 | + } |
| 17 | + |
| 18 | + // Test String method |
| 19 | + if PositiveZero.String() != "0" { |
| 20 | + t.Errorf("String method: expected '0', got '%s'", PositiveZero.String()) |
| 21 | + } |
| 22 | + if NegativeZero.String() != "-0" { |
| 23 | + t.Errorf("String method: expected '-0', got '%s'", NegativeZero.String()) |
| 24 | + } |
| 25 | + if PositiveInfinity.String() != "+Inf" { |
| 26 | + t.Errorf("String method: expected '+Inf', got '%s'", PositiveInfinity.String()) |
| 27 | + } |
| 28 | + if NegativeInfinity.String() != "-Inf" { |
| 29 | + t.Errorf("String method: expected '-Inf', got '%s'", NegativeInfinity.String()) |
| 30 | + } |
| 31 | + if QuietNaN.String() != "NaN" { |
| 32 | + t.Errorf("String method: expected 'NaN', got '%s'", QuietNaN.String()) |
| 33 | + } |
| 34 | + if NegativeQNaN.String() != "-NaN" { |
| 35 | + t.Errorf("String method: expected '-NaN', got '%s'", NegativeQNaN.String()) |
| 36 | + } |
| 37 | + |
| 38 | + // Test GoString method |
| 39 | + if PositiveZero.GoString() != "float16.FromBits(0x0000)" { |
| 40 | + t.Errorf("GoString method: expected 'float16.FromBits(0x0000)', got '%s'", PositiveZero.GoString()) |
| 41 | + } |
| 42 | + |
| 43 | + // Test Class method |
| 44 | + if SignalingNaN.Class() != ClassSignalingNaN { |
| 45 | + t.Errorf("Class method: expected ClassSignalingNaN, got %v", SignalingNaN.Class()) |
| 46 | + } |
| 47 | + if NegativeInfinity.Class() != ClassNegativeInfinity { |
| 48 | + t.Errorf("Class method: expected ClassNegativeInfinity, got %v", NegativeInfinity.Class()) |
| 49 | + } |
| 50 | + if NegativeZero.Class() != ClassNegativeZero { |
| 51 | + t.Errorf("Class method: expected ClassNegativeZero, got %v", NegativeZero.Class()) |
| 52 | + } |
| 53 | + if FromFloat32(-1).Class() != ClassNegativeNormal { |
| 54 | + t.Errorf("Class method: expected ClassNegativeNormal, got %v", FromFloat32(-1).Class()) |
| 55 | + } |
| 56 | + if FromBits(0x8001).Class() != ClassNegativeSubnormal { |
| 57 | + t.Errorf("Class method: expected ClassNegativeSubnormal, got %v", FromBits(0x8001).Class()) |
| 58 | + } |
| 59 | + |
| 60 | + // Test leadingZeros10 |
| 61 | + if leadingZeros10(0) != 10 { |
| 62 | + t.Errorf("leadingZeros10(0): expected 10, got %d", leadingZeros10(0)) |
| 63 | + } |
| 64 | + if leadingZeros10(1) != 3 { |
| 65 | + t.Errorf("leadingZeros10(1): expected 3, got %d", leadingZeros10(1)) |
| 66 | + } |
| 67 | +} |
0 commit comments