From 655e61e3f8dc8de92f0ecad3fdc6c79cf85d7d28 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Mon, 30 Dec 2024 16:33:10 -0300 Subject: src/gobang.go: Add Clamp() --- tests/gobang.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/gobang.go b/tests/gobang.go index 64e9eb5..d67b99f 100644 --- a/tests/gobang.go +++ b/tests/gobang.go @@ -14,6 +14,33 @@ import ( +func test_Clamp() { + TestStart("Clamp()") + + Testing("equal values", func() { + TAssertEqual(Clamp(0, 0, 0), 0) + TAssertEqual(Clamp(1, 1, 1), 1) + TAssertEqual(Clamp(1.0, 1.0, 1.0), 1.0) + }) + + Testing("within range", func() { + TAssertEqual(Clamp(5, 0, 10), 5) + TAssertEqual(Clamp(1.1, 1.0, 1.2), 1.1) + TAssertEqual(Clamp(0, 0, 10), 0) + TAssertEqual(Clamp(10, 0, 10), 10) + }) + + Testing("lower than min", func() { + TAssertEqual(Clamp(1, 2, 3), 2) + TAssertEqual(Clamp(1.0, 1.1, 1.2), 1.1) + }) + + Testing("greater than max", func() { + TAssertEqual(Clamp(1, 11, 10), 10) + TAssertEqual(Clamp(1.2, 1.0, 1.1), 1.1) + }) +} + func test_ValidateSQLTablePrefix() { TestStart("ValidateSQLTablePrefix()") @@ -968,6 +995,7 @@ func test_setHostname() { func MainTest() { + test_Clamp() test_ValidateSQLTablePrefix() test_WrapErrors() test_SomeError() -- cgit v1.2.3