From 0b9a45e16a6a7913edf818c79c834eb863b89ccd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 30 Apr 2025 02:50:58 +0200 Subject: [PATCH] next-prime: Add tests. * tests/test-next-prime.c: New file. * modules/next-prime-tests: New file. --- ChangeLog | 4 ++++ modules/next-prime-tests | 9 ++++++++ tests/test-next-prime.c | 46 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 modules/next-prime-tests create mode 100644 tests/test-next-prime.c diff --git a/ChangeLog b/ChangeLog index 60fbb0c0d0..ee6295754d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2025-04-29 Bruno Haible + next-prime: Add tests. + * tests/test-next-prime.c: New file. + * modules/next-prime-tests: New file. + New module next-prime. * lib/next-prime.h: New file, based on lib/hash.c. * lib/next-prime.c: New file, based on lib/hash.c. diff --git a/modules/next-prime-tests b/modules/next-prime-tests new file mode 100644 index 0000000000..cab1e5227d --- /dev/null +++ b/modules/next-prime-tests @@ -0,0 +1,9 @@ +Files: +tests/test-next-prime.c +tests/macros.h + +configure.ac: + +Makefile.am: +TESTS += test-next-prime +check_PROGRAMS += test-next-prime diff --git a/tests/test-next-prime.c b/tests/test-next-prime.c new file mode 100644 index 0000000000..4a6a25e054 --- /dev/null +++ b/tests/test-next-prime.c @@ -0,0 +1,46 @@ +/* Test of next_prime() function. + Copyright (C) 2025 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2025. */ + +#include + +/* Specification. */ +#include "next-prime.h" + +#include "macros.h" + +int +main () +{ + ASSERT (next_prime (1) == 11); + ASSERT (next_prime (3) == 11); + ASSERT (next_prime (7) == 11); + ASSERT (next_prime (10) == 11); + ASSERT (next_prime (11) == 11); + ASSERT (next_prime (12) == 13); + ASSERT (next_prime (640) == 641); + + ASSERT (next_prime (9551) == 9551); + ASSERT (next_prime (9552) == 9587); + + ASSERT (next_prime (43331) == 43331); + ASSERT (next_prime (43332) == 43391); + + ASSERT (next_prime (1000000) == 1000003); + + return test_exit_status; +} -- 2.39.5