github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/adiantum/math_test.go (about) 1 package adiantum 2 3 import ( 4 "math" 5 "testing" 6 ) 7 8 func Test_abs(t *testing.T) { 9 tests := []struct { 10 arg int 11 want int 12 }{ 13 {0, 0}, 14 {1, 1}, 15 {-1, 1}, 16 {math.MaxInt, math.MaxInt}, 17 {math.MinInt, math.MinInt}, 18 } 19 for _, tt := range tests { 20 t.Run("", func(t *testing.T) { 21 if got := abs(tt.arg); got != tt.want { 22 t.Errorf("abs(%d) = %d, want %d", tt.arg, got, tt.want) 23 } 24 }) 25 } 26 } 27 28 func Test_gcd(t *testing.T) { 29 tests := []struct { 30 arg1 int 31 arg2 int 32 want int 33 }{ 34 {0, 0, 0}, 35 {0, 1, 1}, 36 {1, 0, 1}, 37 {1, 1, 1}, 38 {2, 3, 1}, 39 {42, 56, 14}, 40 {48, -18, 6}, 41 {1e9, 1e9, 1e9}, 42 {1e9, -1e9, 1e9}, 43 {-1e9, -1e9, 1e9}, 44 {math.MaxInt, math.MaxInt, math.MaxInt}, 45 {math.MinInt, math.MinInt, math.MinInt}, 46 } 47 for _, tt := range tests { 48 t.Run("", func(t *testing.T) { 49 if got := gcd(tt.arg1, tt.arg2); got != tt.want { 50 t.Errorf("gcd(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want) 51 } 52 }) 53 } 54 } 55 56 func Test_lcm(t *testing.T) { 57 tests := []struct { 58 arg1 int 59 arg2 int 60 want int 61 }{ 62 {0, 0, 0}, 63 {0, 1, 0}, 64 {1, 0, 0}, 65 {1, 1, 1}, 66 {2, 3, 6}, 67 {42, 56, 168}, 68 {48, -18, 144}, 69 {1e9, 1e9, 1e9}, 70 {1e9, -1e9, 1e9}, 71 {-1e9, -1e9, 1e9}, 72 {math.MaxInt, math.MaxInt, math.MaxInt}, 73 {math.MinInt, math.MinInt, math.MinInt}, 74 } 75 for _, tt := range tests { 76 t.Run("", func(t *testing.T) { 77 if got := lcm(tt.arg1, tt.arg2); got != tt.want { 78 t.Errorf("lcm(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want) 79 } 80 }) 81 } 82 }