[Scummvm-git-logs] scummvm master -> 661e9373e3101477e61619045c98de2befb76601

grisenti noreply at scummvm.org
Thu Jun 1 21:07:52 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
661e9373e3 TEST: Add tests for Common::upperBound


Commit: 661e9373e3101477e61619045c98de2befb76601
    https://github.com/scummvm/scummvm/commit/661e9373e3101477e61619045c98de2befb76601
Author: grisenti (emanuele at grisenti.net)
Date: 2023-06-01T23:07:41+02:00

Commit Message:
TEST: Add tests for Common::upperBound

Changed paths:
    test/common/algorithm.h


diff --git a/test/common/algorithm.h b/test/common/algorithm.h
index cd0b823cecd..4d2a706f16c 100644
--- a/test/common/algorithm.h
+++ b/test/common/algorithm.h
@@ -230,4 +230,44 @@ public:
 			TS_ASSERT_EQUALS(it, nullptr);
 		}
 	}
+
+	void test_upper_bound_element_found() {
+		const auto test = [](const int *first, const int *last, int value, int expected) {
+			const auto it = Common::upperBound(first, last, value);
+			TS_ASSERT(first <= it && it < last);
+			TS_ASSERT_EQUALS(*it, expected);
+		};
+		const int one[] = {1};
+		const int values[] = {2, 3, 4, 10, 50, 100, 900, 1000};
+		test(one, one + ARRAYSIZE(one), 0, 1);
+		test(values, values + ARRAYSIZE(values), 1, 2);
+		test(values, values + ARRAYSIZE(values), 950, 1000);
+		test(values, values + ARRAYSIZE(values), 20, 50);
+	}
+
+	void test_upper_bound_nothing_found() {
+		const int values[] = {1, 2, 3, 6, 8, 10, 20, 50};
+		const auto last = values + ARRAYSIZE(values);
+		{
+			const auto it = Common::upperBound(values, last, 50);
+			TS_ASSERT_EQUALS(it, last);
+		}
+		{
+			const auto it = Common::upperBound(values, last, 100);
+			TS_ASSERT_EQUALS(it, last);
+		}
+	}
+
+	void test_upper_bound_empty_input() {
+		{
+			const int values[] = {1};
+			const auto last = values + ARRAYSIZE(values);
+			const auto it = Common::upperBound(last, last, 1);
+			TS_ASSERT_EQUALS(it, last);
+		}
+		{
+			const auto it = Common::upperBound((int *)nullptr, (int *)nullptr, 1);
+			TS_ASSERT_EQUALS(it, nullptr);
+		}
+	}
 };




More information about the Scummvm-git-logs mailing list