Skip to content

Commit ea349fb

Browse files
committed
test: improve coverage for double/trig_nonjs.mbt
**Disclaimer:** This PR was generated by an LLM agent as part of an experiment. ## Summary ``` coverage of `double/trig_nonjs.mbt`: 78.9% -> 86.4% ```
1 parent 4e63e5a commit ea349fb

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

double/trig_nonjs_test.mbt

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2025 International Digital Economy Academy
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
///|
16+
test "atan2 - zero with x = 0" {
17+
inspect!(1.0.atan2(0.0), content="1.5707963267948966")
18+
inspect!((-1.0).atan2(0.0), content="-1.5707963267948966")
19+
}
20+
21+
///|
22+
test "kernel_sin with iy=0" {
23+
// The line `x + v * (s1 + z * r)` in __kernel_sin function
24+
// is returned when iy == 0
25+
// We need to provide input x that enters this branch
26+
let x = 3.141592653589793 / 4.0
27+
inspect!(@double.sin(x), content="0.7071067811865475")
28+
}
29+
30+
///|
31+
test "asin edge case 1" {
32+
// Test case for x slightly less than 1 (ix >= 0x3FEF3333)
33+
let x = 0.999999
34+
inspect!(@double.asin(x), content="1.5693821131146521")
35+
}
36+
37+
///|
38+
test "atan2 quadrant case" {
39+
// Different quadrants
40+
inspect!((-1.0).atan2(1.0), content="-0.7853981633974483") // quadrant 4
41+
inspect!((-1.0).atan2(-1.0), content="-2.356194490192345") // quadrant 3
42+
inspect!(1.0.atan2(-1.0), content="2.356194490192345") // quadrant 2
43+
}
44+
45+
///|
46+
test "atan of small values" {
47+
let tiny = 1.0e-300 // A value small enough that ix < 0x3e200000 and huge + self > one
48+
let result = @double.atan(tiny)
49+
inspect!(result, content="1e-300")
50+
let very_tiny = 1.0e-500 // Another small value to ensure multiple test cases for the same branch
51+
let result2 = @double.atan(very_tiny)
52+
inspect!(result2, content="0")
53+
}
54+
55+
///|
56+
test "atan2 infinite x case" {
57+
let y = 1.0
58+
inspect!(y.atan2(@double.infinity), content="0")
59+
inspect!((-y).atan2(@double.infinity), content="0")
60+
let b = (-y).atan2(@double.neg_infinity)
61+
inspect!(b, content="-3.141592653589793")
62+
}
63+
64+
///|
65+
test "atan2 for zero and infinity cases" {
66+
let zero = 0.0
67+
let pos_zero = 0.0
68+
let neg_zero = -0.0 // this triggers special case 0 | 1
69+
inspect!(neg_zero.atan2(pos_zero), content="0")
70+
inspect!(neg_zero.atan2(-1.0), content="-3.141592653589793")
71+
let inf = @double.infinity
72+
inspect!(zero.atan2(inf), content="0")
73+
inspect!(zero.atan2(-inf), content="3.141592653589793")
74+
}
75+
76+
///|
77+
test "atan2_large_diff" {
78+
// k > 60
79+
let y = 1.0e100
80+
let x = 0.1
81+
inspect!(y.atan2(x), content="1.5707963267948966")
82+
}
83+
84+
///|
85+
test "atan2_negative_z" {
86+
// m = 1
87+
let y = -1.0
88+
let x = 2.0
89+
inspect!(y.atan2(x), content="-0.4636476090008061")
90+
}
91+
92+
///|
93+
test "atan2_large_negative_x" {
94+
// hx < 0 && k < -60
95+
let y = 0.1
96+
let x = -1.0e100
97+
inspect!(y.atan2(x), content="3.141592653589793")
98+
}
99+
100+
///|
101+
test "kernal_tan edge case" {
102+
let x = 1.5707963267948966
103+
inspect!(x.tan(), content="16331239353195370")
104+
let x = -1.5707963267948966
105+
inspect!(x.tan(), content="-16331239353195370")
106+
}

0 commit comments

Comments
 (0)