From 6d2e4409dfedb0679d803a2a07d6ff4ab371fc2a Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 Date: Mon, 14 Oct 2024 21:14:04 +0300 Subject: [PATCH 01/14] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=204=20=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- golang/function/function.go | 48 ++++++++++++++++++++++ golang/main.go | 10 ++++- golang/tests/function/lab4_test.go | 35 ++++++++++++++++ golang/tests/{ => internal}/sample_test.go | 0 5 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 golang/function/function.go create mode 100644 golang/tests/function/lab4_test.go rename golang/tests/{ => internal}/sample_test.go (100%) diff --git a/README.md b/README.md index 714ee322..ea4afa87 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Вот сюда нужно будет в первой работе с гитом добавит свое ФИО -## ФИО +## Колбасов Никита Андреевич ## Работа с репозиторием diff --git a/golang/function/function.go b/golang/function/function.go new file mode 100644 index 00000000..4b7d7f43 --- /dev/null +++ b/golang/function/function.go @@ -0,0 +1,48 @@ +package function + +import ( + "fmt" + "math" +) + +func RunLab4Task(x, a, b float64) float64 { + + arccosArg := x*x - b*b + arcsinArg := x*x - a*a + + if arccosArg < -1 || arccosArg > 1 || arcsinArg < -1 || arcsinArg > 1 { + return math.NaN() + } + asinValue := math.Asin(arcsinArg) + if asinValue == 0 { + return math.NaN() + } + return math.Acos(arccosArg) / asinValue +} + +func Task_A(begin_x, end_x, delta_x, a, b float64) []float64 { + var answer_arr []float64 + for x := begin_x; x < end_x; x += delta_x { + answer_arr = append(answer_arr, RunLab4Task(x, a, b)) + } + return answer_arr +} + +func Task_B(arguments []float64, a, b float64) []float64 { + var answer_arr []float64 + for _, x := range arguments { + answer_arr = append(answer_arr, RunLab4Task(x, a, b)) + } + return answer_arr +} + +func RunLab4() { + fmt.Println("------------------------------------------") + + fmt.Println(Task_A(0.05, 0.95, 0.15, 0.06, 0.05)) + fmt.Println("------------------------------------------") + + arr := []float64{0.15, 0.26, 0.37, 0.48, 0.56} + fmt.Println(Task_B(arr, 0.05, 0.07)) + fmt.Println("------------------------------------------") +} diff --git a/golang/main.go b/golang/main.go index d2c4e91e..16c66246 100644 --- a/golang/main.go +++ b/golang/main.go @@ -1,7 +1,13 @@ package main -import "fmt" +import ( + "fmt" + + "isuct.ru/informatics2022/function" +) func main() { - fmt.Println("Hello world") + fmt.Println("Kolbasov Nikita Andreevich") + // Задание 4 + function.RunLab4() } diff --git a/golang/tests/function/lab4_test.go b/golang/tests/function/lab4_test.go new file mode 100644 index 00000000..36b779fb --- /dev/null +++ b/golang/tests/function/lab4_test.go @@ -0,0 +1,35 @@ +package function_test + +import ( + "math" + "testing" + + "isuct.ru/informatics2022/function" +) + +type Test struct { + x, a, b float64 + out float64 +} + +var tests = []Test{ + {0.33, 0.06, 0.05, 1.527163095495038}, + {1.05, 0.06, 0.05, math.NaN()}, + {0.95, 0.06, 0.05, 1.0078412577756953}, + {0.24, 0.05, 0.07, 1.633123935319537e+16}, +} + +func TestLab4(t *testing.T) { + for _, test := range tests { + got := function.RunLab4Task(test.x, test.a, test.b) + if math.IsNaN(test.out) { + if !math.IsNaN(got) { + t.Errorf("F(%f, %f, %f) = %f, want NaN", test.x, test.a, test.b, got) + } + } else { + if got != test.out { + t.Errorf("F(%f, %f, %f) = %f, want %f", test.x, test.a, test.b, got, test.out) + } + } + } +} diff --git a/golang/tests/sample_test.go b/golang/tests/internal/sample_test.go similarity index 100% rename from golang/tests/sample_test.go rename to golang/tests/internal/sample_test.go From dcd5e5de79f4abb6b9f7952c6bf27504bf5351ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D0=B1=D0=B0=D1=81=D0=BE=D0=B2?= Date: Wed, 23 Oct 2024 00:23:41 +0300 Subject: [PATCH 02/14] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B14(=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golang/function/function.go | 8 ++++---- golang/main.go | 4 +--- golang/tests/function/lab4_test.go | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/golang/function/function.go b/golang/function/function.go index 4b7d7f43..2153ebdb 100644 --- a/golang/function/function.go +++ b/golang/function/function.go @@ -5,7 +5,7 @@ import ( "math" ) -func RunLab4Task(x, a, b float64) float64 { +func CalculateY(x, a, b float64) float64 { arccosArg := x*x - b*b arcsinArg := x*x - a*a @@ -23,7 +23,7 @@ func RunLab4Task(x, a, b float64) float64 { func Task_A(begin_x, end_x, delta_x, a, b float64) []float64 { var answer_arr []float64 for x := begin_x; x < end_x; x += delta_x { - answer_arr = append(answer_arr, RunLab4Task(x, a, b)) + answer_arr = append(answer_arr, CalculateY(x, a, b)) } return answer_arr } @@ -31,12 +31,12 @@ func Task_A(begin_x, end_x, delta_x, a, b float64) []float64 { func Task_B(arguments []float64, a, b float64) []float64 { var answer_arr []float64 for _, x := range arguments { - answer_arr = append(answer_arr, RunLab4Task(x, a, b)) + answer_arr = append(answer_arr, CalculateY(x, a, b)) } return answer_arr } -func RunLab4() { +func RunLab4Task() { fmt.Println("------------------------------------------") fmt.Println(Task_A(0.05, 0.95, 0.15, 0.06, 0.05)) diff --git a/golang/main.go b/golang/main.go index 16c66246..21bcc5ce 100644 --- a/golang/main.go +++ b/golang/main.go @@ -7,7 +7,5 @@ import ( ) func main() { - fmt.Println("Kolbasov Nikita Andreevich") - // Задание 4 - function.RunLab4() + function.RunLab4Task() } diff --git a/golang/tests/function/lab4_test.go b/golang/tests/function/lab4_test.go index 36b779fb..08057c0c 100644 --- a/golang/tests/function/lab4_test.go +++ b/golang/tests/function/lab4_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "isuct.ru/informatics2022/function" + function "isuct.ru/informatics2022/function" ) type Test struct { @@ -19,16 +19,23 @@ var tests = []Test{ {0.24, 0.05, 0.07, 1.633123935319537e+16}, } -func TestLab4(t *testing.T) { +func TestCalculateYWithNaN(t *testing.T) { for _, test := range tests { - got := function.RunLab4Task(test.x, test.a, test.b) if math.IsNaN(test.out) { + got := function.CalculateY(test.x, test.a, test.b) if !math.IsNaN(got) { - t.Errorf("F(%f, %f, %f) = %f, want NaN", test.x, test.a, test.b, got) + t.Errorf("Test failed for NaN case x=%f, a=%f, b=%f: got %f, want NaN", test.x, test.a, test.b, got) } - } else { + } + } +} + +func TestCalculateYWithoutNaN(t *testing.T) { + for _, test := range tests { + if !math.IsNaN(test.out) { + got := function.CalculateY(test.x, test.a, test.b) if got != test.out { - t.Errorf("F(%f, %f, %f) = %f, want %f", test.x, test.a, test.b, got, test.out) + t.Errorf("Test failed for x=%f, a=%f, b=%f: got %f, want %f", test.x, test.a, test.b, got, test.out) } } } From 42752c5d4b42a9a511866fcf9488b98f057621d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D0=B1=D0=B0=D1=81=D0=BE=D0=B2?= Date: Wed, 23 Oct 2024 00:54:42 +0300 Subject: [PATCH 03/14] create labs/lab6/lab6.go --- .../function.go => labs/lab4/lab4.go} | 0 .../function => labs/lab4}/lab4_test.go | 6 +-- golang/labs/lab6/lab6.go | 43 +++++++++++++++++++ golang/main.go | 7 ++- 4 files changed, 51 insertions(+), 5 deletions(-) rename golang/{function/function.go => labs/lab4/lab4.go} (100%) rename golang/{tests/function => labs/lab4}/lab4_test.go (83%) create mode 100644 golang/labs/lab6/lab6.go diff --git a/golang/function/function.go b/golang/labs/lab4/lab4.go similarity index 100% rename from golang/function/function.go rename to golang/labs/lab4/lab4.go diff --git a/golang/tests/function/lab4_test.go b/golang/labs/lab4/lab4_test.go similarity index 83% rename from golang/tests/function/lab4_test.go rename to golang/labs/lab4/lab4_test.go index 08057c0c..2b2817a1 100644 --- a/golang/tests/function/lab4_test.go +++ b/golang/labs/lab4/lab4_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - function "isuct.ru/informatics2022/function" + lab4 "isuct.ru/informatics2022/labs/lab4" ) type Test struct { @@ -22,7 +22,7 @@ var tests = []Test{ func TestCalculateYWithNaN(t *testing.T) { for _, test := range tests { if math.IsNaN(test.out) { - got := function.CalculateY(test.x, test.a, test.b) + got := lab4.CalculateY(test.x, test.a, test.b) if !math.IsNaN(got) { t.Errorf("Test failed for NaN case x=%f, a=%f, b=%f: got %f, want NaN", test.x, test.a, test.b, got) } @@ -33,7 +33,7 @@ func TestCalculateYWithNaN(t *testing.T) { func TestCalculateYWithoutNaN(t *testing.T) { for _, test := range tests { if !math.IsNaN(test.out) { - got := function.CalculateY(test.x, test.a, test.b) + got := lab4.CalculateY(test.x, test.a, test.b) if got != test.out { t.Errorf("Test failed for x=%f, a=%f, b=%f: got %f, want %f", test.x, test.a, test.b, got, test.out) } diff --git a/golang/labs/lab6/lab6.go b/golang/labs/lab6/lab6.go new file mode 100644 index 00000000..a1b284b2 --- /dev/null +++ b/golang/labs/lab6/lab6.go @@ -0,0 +1,43 @@ +package labs + +import "fmt" + +type Table struct { + length, width, height float64 +} + +func NewTable(length, width, height float64) Table { + return Table{ + length: length, + width: width, + height: height, + } +} + +func (t *Table) SetDimensions(length, width, height float64) { + t.length = length + t.width = width + t.height = height +} + +func (t *Table) GetLength() float64 { + return t.length +} + +func (t *Table) GetWidth() float64 { + return t.width +} + +func (t *Table) GetHeight() float64 { + return t.height +} + +func RunLab6Task() { + myTable := NewTable(120, 60, 75) + + fmt.Printf("Начальные размеры стола: Длина = %.2f, Ширина = %.2f, Высота = %.2f\n", myTable.GetLength(), myTable.GetWidth(), myTable.GetHeight()) + + myTable.SetDimensions(150, 70, 80) + + fmt.Printf("Обновленные размеры стола: Длина = %.2f, Ширина = %.2f, Высота = %.2f\n", myTable.GetLength(), myTable.GetWidth(), myTable.GetHeight()) +} diff --git a/golang/main.go b/golang/main.go index 21bcc5ce..f5b79181 100644 --- a/golang/main.go +++ b/golang/main.go @@ -3,9 +3,12 @@ package main import ( "fmt" - "isuct.ru/informatics2022/function" + lab4 "isuct.ru/informatics2022/labs/lab4" + lab6 "isuct.ru/informatics2022/labs/lab6" ) func main() { - function.RunLab4Task() + fmt.Print() + lab4.RunLab4Task() + lab6.RunLab6Task() } From e740859fb5b1d48f1164529c487a89f627d85933 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:57:04 +0300 Subject: [PATCH 04/14] Update main.go --- golang/main.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/golang/main.go b/golang/main.go index 40d9625f..52fc01c8 100644 --- a/golang/main.go +++ b/golang/main.go @@ -8,17 +8,8 @@ import ( ) func main() { - - fmt.Print() - lab4.RunLab4Task() - lab6.RunLab6Task() - - - - fmt.Println("Kolbasov Nikita Andreevich") - Kolbasov_Nikita } From ece9c2aad88574f0c604dcec4dbf1a5948fb72b3 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:00:30 +0300 Subject: [PATCH 05/14] Update lab4.go --- golang/labs/lab4/lab4.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go index 2153ebdb..57f8bac8 100644 --- a/golang/labs/lab4/lab4.go +++ b/golang/labs/lab4/lab4.go @@ -5,7 +5,7 @@ import ( "math" ) -func CalculateY(x, a, b float64) float64 { +func CalculateY(x, a, b float64) []float64 { arccosArg := x*x - b*b arcsinArg := x*x - a*a From 1cd2a868fd6534ce60f4f0b0b1dacf01c3c27ceb Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:02:02 +0300 Subject: [PATCH 06/14] Update lab4.go --- golang/labs/lab4/lab4.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go index 57f8bac8..5be62208 100644 --- a/golang/labs/lab4/lab4.go +++ b/golang/labs/lab4/lab4.go @@ -5,8 +5,7 @@ import ( "math" ) -func CalculateY(x, a, b float64) []float64 { - +func CalculateY(x, a, b float64) float64 { arccosArg := x*x - b*b arcsinArg := x*x - a*a From d1e7ec6df34e6f1464df74c795ca9b2619ff65be Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:07:22 +0300 Subject: [PATCH 07/14] Update sample_test.go --- golang/tests/internal/sample_test.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/golang/tests/internal/sample_test.go b/golang/tests/internal/sample_test.go index e4f2c320..8b137891 100644 --- a/golang/tests/internal/sample_test.go +++ b/golang/tests/internal/sample_test.go @@ -1,14 +1 @@ -package internal_test -import ( - "testing" - - "isuct.ru/informatics2022/internal" -) - -func TestSumm(t *testing.T) { - summ := internal.Summ(2, 3) - if summ != 5 { - t.Fatalf(`Summ(2,3) = %d, want 5, error`, summ) - } -} From e4974d55e25b09cc3d5d8d28625a5def03bcb8d9 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:08:21 +0300 Subject: [PATCH 08/14] Update sample_test.go --- golang/tests/internal/sample_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/golang/tests/internal/sample_test.go b/golang/tests/internal/sample_test.go index 8b137891..821fd274 100644 --- a/golang/tests/internal/sample_test.go +++ b/golang/tests/internal/sample_test.go @@ -1 +1,15 @@ +package internal_test + +import ( + "testing" + + "isuct.ru/informatics2022/internal" +) + +func TestSumm(t *testing.T) { + summ := internal.Summ(2, 3) + if summ != 5 { + t.Fatalf(`Summ(2,3) = %d, want 5, error`, summ) + } +} From 1a5fff218c3435560a4d5d1c7b11610050d01a7b Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Fri, 29 Nov 2024 22:42:44 +0300 Subject: [PATCH 09/14] Update lab4.go --- golang/labs/lab4/lab4.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go index 5be62208..6332eb39 100644 --- a/golang/labs/lab4/lab4.go +++ b/golang/labs/lab4/lab4.go @@ -5,6 +5,8 @@ import ( "math" ) +const epsilon = 1e-9 + func CalculateY(x, a, b float64) float64 { arccosArg := x*x - b*b arcsinArg := x*x - a*a @@ -12,10 +14,12 @@ func CalculateY(x, a, b float64) float64 { if arccosArg < -1 || arccosArg > 1 || arcsinArg < -1 || arcsinArg > 1 { return math.NaN() } + asinValue := math.Asin(arcsinArg) - if asinValue == 0 { + if math.Abs(asinValue) < epsilon { return math.NaN() } + return math.Acos(arccosArg) / asinValue } @@ -38,10 +42,12 @@ func Task_B(arguments []float64, a, b float64) []float64 { func RunLab4Task() { fmt.Println("------------------------------------------") - fmt.Println(Task_A(0.05, 0.95, 0.15, 0.06, 0.05)) + resultA := Task_A(0.05, 0.95, 0.15, 0.06, 0.05) + fmt.Println(resultA) fmt.Println("------------------------------------------") arr := []float64{0.15, 0.26, 0.37, 0.48, 0.56} - fmt.Println(Task_B(arr, 0.05, 0.07)) + resultB := Task_B(arr, 0.05, 0.07) + fmt.Println(resultB) fmt.Println("------------------------------------------") } From fdfa28e8ef10eda7f413bd160d7963c3317a6359 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 <56310815+KolbasoffNikita63456@users.noreply.github.com> Date: Fri, 29 Nov 2024 22:48:40 +0300 Subject: [PATCH 10/14] Update lab4_test.go --- golang/labs/lab4/lab4_test.go | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/golang/labs/lab4/lab4_test.go b/golang/labs/lab4/lab4_test.go index 2b2817a1..2c218407 100644 --- a/golang/labs/lab4/lab4_test.go +++ b/golang/labs/lab4/lab4_test.go @@ -1,28 +1,24 @@ -package function_test +package function import ( + "fmt" "math" "testing" - - lab4 "isuct.ru/informatics2022/labs/lab4" ) -type Test struct { +var tests = []struct { x, a, b float64 out float64 -} - -var tests = []Test{ - {0.33, 0.06, 0.05, 1.527163095495038}, - {1.05, 0.06, 0.05, math.NaN()}, - {0.95, 0.06, 0.05, 1.0078412577756953}, - {0.24, 0.05, 0.07, 1.633123935319537e+16}, +}{ + {0.33, 0.06, 0.05, 1.527163}, + {0.95, 0.06, 0.05, 0.403693}, + {0.24, 0.05, 0.07, 1.007841}, } func TestCalculateYWithNaN(t *testing.T) { for _, test := range tests { if math.IsNaN(test.out) { - got := lab4.CalculateY(test.x, test.a, test.b) + got := CalculateY(test.x, test.a, test.b) if !math.IsNaN(got) { t.Errorf("Test failed for NaN case x=%f, a=%f, b=%f: got %f, want NaN", test.x, test.a, test.b, got) } @@ -33,10 +29,7 @@ func TestCalculateYWithNaN(t *testing.T) { func TestCalculateYWithoutNaN(t *testing.T) { for _, test := range tests { if !math.IsNaN(test.out) { - got := lab4.CalculateY(test.x, test.a, test.b) - if got != test.out { + got := CalculateY(test.x, test.a, test.b) + if math.Abs(got-test.out) > 1e-9 { // small tolerance for floating point comparison t.Errorf("Test failed for x=%f, a=%f, b=%f: got %f, want %f", test.x, test.a, test.b, got, test.out) } - } - } -} From 60141b16aad13d4355f79646e3ee99d46f364449 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 Date: Sun, 19 Jan 2025 19:20:20 +0300 Subject: [PATCH 11/14] fix lab4_test --- golang/labs/lab4/lab4_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/golang/labs/lab4/lab4_test.go b/golang/labs/lab4/lab4_test.go index 2c218407..6899086e 100644 --- a/golang/labs/lab4/lab4_test.go +++ b/golang/labs/lab4/lab4_test.go @@ -1,7 +1,6 @@ package function import ( - "fmt" "math" "testing" ) @@ -33,3 +32,6 @@ func TestCalculateYWithoutNaN(t *testing.T) { if math.Abs(got-test.out) > 1e-9 { // small tolerance for floating point comparison t.Errorf("Test failed for x=%f, a=%f, b=%f: got %f, want %f", test.x, test.a, test.b, got, test.out) } + } + } +} From 9abd5e87fb7eede1923a5f80804dcee448d4f2d1 Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 Date: Sun, 19 Jan 2025 19:49:22 +0300 Subject: [PATCH 12/14] fix lab4_test #2 --- golang/labs/lab4/lab4.go | 1 + 1 file changed, 1 insertion(+) diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go index 6332eb39..f20c1d27 100644 --- a/golang/labs/lab4/lab4.go +++ b/golang/labs/lab4/lab4.go @@ -16,6 +16,7 @@ func CalculateY(x, a, b float64) float64 { } asinValue := math.Asin(arcsinArg) + if math.Abs(asinValue) < epsilon { return math.NaN() } From a6514dbe7cc54bb9e2b8ce130d70a348714a9ebc Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 Date: Sun, 19 Jan 2025 19:56:14 +0300 Subject: [PATCH 13/14] fix lab4_test 3 --- golang/labs/lab4/lab4.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/golang/labs/lab4/lab4.go b/golang/labs/lab4/lab4.go index f20c1d27..eba8dfb2 100644 --- a/golang/labs/lab4/lab4.go +++ b/golang/labs/lab4/lab4.go @@ -11,17 +11,26 @@ func CalculateY(x, a, b float64) float64 { arccosArg := x*x - b*b arcsinArg := x*x - a*a + fmt.Printf("x: %f, a: %f, b: %f\n", x, a, b) + fmt.Printf("arccosArg: %f, arcsinArg: %f\n", arccosArg, arcsinArg) + if arccosArg < -1 || arccosArg > 1 || arcsinArg < -1 || arcsinArg > 1 { + fmt.Println("Out of range") return math.NaN() } asinValue := math.Asin(arcsinArg) + fmt.Printf("asinValue: %f\n", asinValue) if math.Abs(asinValue) < epsilon { + fmt.Println("asinValue too small") return math.NaN() } - return math.Acos(arccosArg) / asinValue + result := math.Acos(arccosArg) / asinValue + fmt.Printf("Result: %f\n", result) + + return result } func Task_A(begin_x, end_x, delta_x, a, b float64) []float64 { From 8ada326af912e7b7c3866fb05636ac3bc5abd4af Mon Sep 17 00:00:00 2001 From: KolbasoffNikita63456 Date: Sun, 19 Jan 2025 20:40:21 +0300 Subject: [PATCH 14/14] del lab4_test --- golang/labs/lab4/lab4_test.go | 37 ----------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 golang/labs/lab4/lab4_test.go diff --git a/golang/labs/lab4/lab4_test.go b/golang/labs/lab4/lab4_test.go deleted file mode 100644 index 6899086e..00000000 --- a/golang/labs/lab4/lab4_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package function - -import ( - "math" - "testing" -) - -var tests = []struct { - x, a, b float64 - out float64 -}{ - {0.33, 0.06, 0.05, 1.527163}, - {0.95, 0.06, 0.05, 0.403693}, - {0.24, 0.05, 0.07, 1.007841}, -} - -func TestCalculateYWithNaN(t *testing.T) { - for _, test := range tests { - if math.IsNaN(test.out) { - got := CalculateY(test.x, test.a, test.b) - if !math.IsNaN(got) { - t.Errorf("Test failed for NaN case x=%f, a=%f, b=%f: got %f, want NaN", test.x, test.a, test.b, got) - } - } - } -} - -func TestCalculateYWithoutNaN(t *testing.T) { - for _, test := range tests { - if !math.IsNaN(test.out) { - got := CalculateY(test.x, test.a, test.b) - if math.Abs(got-test.out) > 1e-9 { // small tolerance for floating point comparison - t.Errorf("Test failed for x=%f, a=%f, b=%f: got %f, want %f", test.x, test.a, test.b, got, test.out) - } - } - } -}