github.com/alibabacloud-go/tea@v1.3.10/dara/math_test.go (about) 1 package dara 2 3 import ( 4 "testing" 5 ) 6 7 // TestRandom tests the Random function to ensure it returns a value in the range [0.0, 1.0) 8 func TestRandom(t *testing.T) { 9 for i := 0; i < 100; i++ { 10 val := Random() 11 if val < 0.0 || val >= 1.0 { 12 t.Errorf("Random() = %v, want [0.0, 1.0)", val) 13 } 14 } 15 } 16 17 // TestFloor tests the Floor function with various numeric inputs 18 func TestFloor(t *testing.T) { 19 tests := []struct { 20 input Number 21 expected int 22 }{ 23 {3.7, 3}, 24 {-3.7, -4}, 25 {0.9, 0}, 26 {0.0, 0}, 27 {-0.9, -1}, 28 {int64(3), 3}, 29 {int32(-3), -3}, 30 } 31 32 for _, tt := range tests { 33 result := Floor(tt.input) 34 if result != tt.expected { 35 t.Errorf("Floor(%v) = %v, want %v", tt.input, result, tt.expected) 36 } 37 } 38 } 39 40 // TestRound tests the Round function with various numeric inputs 41 func TestRound(t *testing.T) { 42 tests := []struct { 43 input Number 44 expected int 45 }{ 46 {3.7, 4}, 47 {-3.7, -4}, 48 {2.5, 3}, 49 {2.4, 2}, 50 {-2.5, -3}, 51 {0.0, 0}, 52 {int64(4), 4}, 53 {int32(-4), -4}, 54 } 55 56 for _, tt := range tests { 57 result := Round(tt.input) 58 if result != tt.expected { 59 t.Errorf("Round(%v) = %v, want %v", tt.input, result, tt.expected) 60 } 61 } 62 }