From b4985b43661521454c1e1f506d539736c1c2229d Mon Sep 17 00:00:00 2001 From: Kolezhuk Alvian <408819@edu.itmo.ru> Date: Fri, 26 Sep 2025 23:20:21 +0300 Subject: [PATCH 1/2] add tests for IsComplexEqual --- README.md | 2 +- tests/main_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb52a20..3e4b62a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ func ShiftPointer(pointer **int, shift int) { panic("not implemented") } -// IsComplexEqual compares two complex numbers and determines if they are equal. +// IsComplexEqual compares two complex numbers and determines if they belong to the same eps-neighborhood. func IsComplexEqual(a, b complex128) bool { panic("not implemented") } diff --git a/tests/main_test.go b/tests/main_test.go index 324612c..dd0e26c 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -408,6 +408,18 @@ func TestIsComplexEqual(t *testing.T) { b: complex(-42, math.Inf(1)), expected: false, }, + { + name: "+inf +inf real equal with precision", + a: complex(math.Inf(1), 1), + b: complex(math.Inf(1), 1.000000001), + expected: true, + }, + { + name: "+inf +inf imag equal with precision", + a: complex(1, math.Inf(1)), + b: complex(1.000000001, math.Inf(1)), + expected: true, + }, } for _, tc := range testCases { From 12e91bf810188b1f7effaaaafd9a0db9c360debc Mon Sep 17 00:00:00 2001 From: Kolezhuk Alvian <408819@edu.itmo.ru> Date: Fri, 26 Sep 2025 23:30:30 +0300 Subject: [PATCH 2/2] add solution for IsComplexEqual --- solution/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solution/main.go diff --git a/solution/main.go b/solution/main.go new file mode 100644 index 0000000..2f7c280 --- /dev/null +++ b/solution/main.go @@ -0,0 +1,11 @@ +package digest + +import "math" + +func IsComplexEqual(a, b complex128) bool { + return isFloatEqual(real(a), real(b)) && isFloatEqual(imag(a), imag(b)) +} + +func isFloatEqual(a, b float64) bool { + return a == b || math.Abs(a-b) < 1e-6 +}