xref: /freebsd/usr.bin/factor/tests/primes_tests.sh (revision c60be9ea6b1ecef6e77096601660f9573ec59a26)
1#
2# SPDX-License-Identifier: BSD-2-Clause
3#
4# Copyright 2023 (C) Enji Cooper
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26
27atf_test_case invalid_range
28invalid_range_head()
29{
30	atf_set "descr" "Verify that invalid ranges are not allowed."
31}
32invalid_range_body()
33{
34	atf_check -s not-exit:0 -e inline:"primes: start value must be less than stop value.\n" primes -- 2 1
35}
36
37atf_test_case negative_numbers_not_allowed
38negative_numbers_not_allowed_head()
39{
40	atf_set "descr" "Verify that negative numbers are not allowed."
41}
42negative_numbers_not_allowed_body()
43{
44	atf_check -s not-exit:0 -e inline:"primes: negative numbers aren't permitted.\n" primes -- -1 0
45}
46
47atf_test_case no_primes_between_between_20_and_22
48no_primes_between_between_20_and_22_head()
49{
50	atf_set "descr" "Show that no primes exist between [20, 22]."
51}
52
53no_primes_between_between_20_and_22_body()
54{
55	atf_check primes 20 22
56}
57
58atf_test_case primes_in_20_to_50_range
59primes_in_20_to_50_range_head()
60{
61	atf_set "descr" "Find all primes between [20, 50]."
62}
63
64primes_in_20_to_50_range_body()
65{
66	atf_check -o inline:"23\n29\n31\n37\n41\n43\n47\n" primes 20 50
67}
68
69atf_init_test_cases()
70{
71	atf_add_test_case invalid_range
72	atf_add_test_case negative_numbers_not_allowed
73	atf_add_test_case no_primes_between_between_20_and_22
74	atf_add_test_case primes_in_20_to_50_range
75}
76