summaryrefslogtreecommitdiff
path: root/eclass/tests
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2021-08-17 11:36:49 +0100
committerV3n3RiX <venerix@redcorelinux.org>2021-08-17 11:36:49 +0100
commite2db47eaae00ec33f8971db44b68645c5d3b9590 (patch)
tree3ec0cf16ddb5854017e134fabebe14bf8cb94a34 /eclass/tests
parent616579b5d773c50af31ee56f00105d96ce641ca2 (diff)
gentoo resync : 17.08.2021
Diffstat (limited to 'eclass/tests')
-rwxr-xr-xeclass/tests/qmail.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/eclass/tests/qmail.sh b/eclass/tests/qmail.sh
new file mode 100755
index 000000000000..3520ed2a9d5b
--- /dev/null
+++ b/eclass/tests/qmail.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright 2020-2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh
+
+inherit qmail
+
+# some numbers are blocked because they are to small even if prime
+test_low_numbers() {
+ tbegin "low numbers"
+
+ for i in $(seq 0 6); do
+ if is_prime ${i}; then
+ return tend 1 "${i} badly accepted"
+ fi
+ done
+
+ tend 0
+}
+
+# test a given number for being prime
+check_prime_number() {
+ # use factor from coreutils to count the factors
+ if [[ $(factor $1 | cut -d: -f2 | wc -w) == 1 ]]; then
+ return $(is_prime $1)
+ else
+ return $(is_prime $1 && false || true)
+ fi
+}
+
+test_primes() {
+ tbegin "factorizations from ${1} to ${2}"
+
+ for i in $(seq ${1:?} ${2:?}); do
+ if ! check_prime_number $i; then
+ tend 1 "${i} returned bad factorization"
+ return 1
+ fi
+ done
+
+ tend 0
+}
+
+test_low_numbers
+test_primes 7 99
+for i in $(seq 100 100 1000); do
+ test_primes $i $((i + 99))
+done
+
+texit