From 28479be939ec53a758feef5ad50c4fab9b6531d2 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 27 Jun 2023 16:48:29 +0200 Subject: [PATCH] Add test for findDirection function Add a new test file, direction_test.go, to test the findDirection function with various input cases. This change helps ensure the reliability and expected functionality of the findDirection function. --- direction_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 direction_test.go diff --git a/direction_test.go b/direction_test.go new file mode 100644 index 0000000..6c92fe8 --- /dev/null +++ b/direction_test.go @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Winni Neessen +// +// SPDX-License-Identifier: MIT + +package meteologix + +import ( + "testing" +) + +func TestFindDirection(t *testing.T) { + // Prepare test cases + tt := []struct { + v float64 + dm map[float64]string + er string + }{ + {15, WindDirAbbrMap, "NbE"}, + {47, WindDirAbbrMap, "NE"}, + {200, WindDirAbbrMap, "SSW"}, + {330, WindDirAbbrMap, "NWbN"}, + {15, WindDirFullMap, "North by East"}, + {47, WindDirFullMap, "Northeast"}, + {200, WindDirFullMap, "South-Southwest"}, + {330, WindDirFullMap, "Northwest by North"}, + } + + // Run tests + for _, tc := range tt { + t.Run("", func(t *testing.T) { + r := findDirection(tc.v, tc.dm) + if tc.er != r { + t.Errorf("findDirection failed, expected: %s, got: %s", tc.er, r) + } + }) + } +}