From 8b0c43475a764080299f1d69efc2cef0db7b6c66 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 12 May 2022 16:29:48 +0200 Subject: Add saturate_add() that generalizes size_add() --- src/test/test-macro.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/test/test-macro.c') diff --git a/src/test/test-macro.c b/src/test/test-macro.c index ba319953cd..c39f64b385 100644 --- a/src/test/test-macro.c +++ b/src/test/test-macro.c @@ -6,6 +6,15 @@ #include "macro.h" #include "tests.h" +TEST(saturate_add) { + assert_se(saturate_add(1, 2, UINT8_MAX) == 3); + assert_se(saturate_add(1, UINT8_MAX-2, UINT8_MAX) == UINT8_MAX-1); + assert_se(saturate_add(1, UINT8_MAX-1, UINT8_MAX) == UINT8_MAX); + assert_se(saturate_add(1, UINT8_MAX, UINT8_MAX) == UINT8_MAX); + assert_se(saturate_add(2, UINT8_MAX, UINT8_MAX) == UINT8_MAX); + assert_se(saturate_add(60, 60, 50) == 50); +} + TEST(align_power2) { unsigned long i, p2; -- cgit v1.2.3