Skip to content

Commit 96a36ce

Browse files
Smit-createAastha Singh
andcommitted
Add tests
Co-Authored-By: Aastha Singh <btech10014.18@bitmesra.ac.in>
1 parent 5e4acd7 commit 96a36ce

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

integration_tests/test_math.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from math import (factorial, isqrt, perm, comb, degrees, radians, exp, pow,
22
ldexp, fabs, gcd, lcm, floor, ceil, remainder, expm1, fmod, log1p, trunc,
3-
modf, fsum, prod)
3+
modf, fsum, prod, dist)
44
import math
55
from ltypes import i32, i64, f32, f64
66

@@ -220,6 +220,14 @@ def test_prod():
220220
res = prod(arr_f64)
221221
assert abs(res - 80.64) < eps
222222

223+
def test_dist():
224+
x: list[f64]
225+
y: list[f64]
226+
eps: f64 = 1e-12
227+
x = [1.0, 2.2, 3.333, 4.0, 5.0]
228+
y = [6.1, 7.2, 8.0, 9.0, 10.0]
229+
assert abs(dist(x, y) - 11.081105044173166) < eps
230+
223231
def test_modf():
224232
i: f64
225233
i = 3.14
@@ -268,6 +276,7 @@ def check():
268276
test_trunc()
269277
test_fsum()
270278
test_prod()
279+
test_dist()
271280
test_modf()
272281
test_issue_1242()
273282

src/runtime/math.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def dist(x: list[f64], y: list[f64]) -> f64:
218218

219219
i: i32
220220
for i in range(len(x)):
221-
res += (x[i] - y[i]) ** 2
221+
res += (x[i] - y[i]) * (x[i] - y[i])
222222
return res**0.5
223223

224224

0 commit comments

Comments
 (0)