]> Savannah Git Hosting - gnulib.git/commitdiff
next-prime: Add tests.
authorBruno Haible <bruno@clisp.org>
Wed, 30 Apr 2025 00:50:58 +0000 (02:50 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 30 Apr 2025 00:50:58 +0000 (02:50 +0200)
* tests/test-next-prime.c: New file.
* modules/next-prime-tests: New file.

ChangeLog
modules/next-prime-tests [new file with mode: 0644]
tests/test-next-prime.c [new file with mode: 0644]

index 60fbb0c0d0227237d5a852770f04c85baeb6650f..ee6295754defdff888067555590e344f88562397 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2025-04-29  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..cab1e52
--- /dev/null
@@ -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 (file)
index 0000000..4a6a25e
--- /dev/null
@@ -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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2025.  */
+
+#include <config.h>
+
+/* 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;
+}