#!/bin/bash # Create correctness test files touch test-empty cat < test-whitespace EOF cat < test-single 1 EOF cat < test-single-neg -11 EOF cat < test-primes 2 3 5 7 11 13 19 23 EOF # Create performance test files M3=multiples-3.txt if [ ! -e $M3 ] then echo "Creating $M3 ... be patient!" if type -P jot &> /dev/null then jot - 4294967298 5583457485 3 > $M3 else seq 4294967298 3 5583457485 > $M3 fi fi # Test helpers find_it() { ./$* || echo Failed $* } miss_it() { ! ./$* || echo Failed $* } test_correctness() { echo "Running $1 correctness tests" search=$1 miss_it $search 0 test-empty miss_it $search 0 test-whitespace find_it $search 1 test-single miss_it $search 0 test-single miss_it $search 11 test-single find_it $search -11 test-single-neg miss_it $search -1 test-single-neg miss_it $search 11 test-single-neg for v in 2 3 5 7 11 13 19 23 ; do find_it $search $v test-primes ; done for v in 1 4 10 22 24 ; do miss_it $search $v test-primes ; done } test_performance() { echo "Running $1 performance tests" search=$1 time \ ( miss_it $search 4294967295 $M3 ; \ find_it $search 4294967298 $M3 ; \ miss_it $search 4294967299 $M3 ; \ miss_it $search 4294967300 $M3 ; \ miss_it $search 4939212389 $M3 ; \ find_it $search 4939212390 $M3 ; \ miss_it $search 4939212391 $M3 ; \ find_it $search 5583457485 $M3 ; \ miss_it $search 5583457486 $M3 ) } # Note: Boost is installed in /opt/local on my machine. # Change the GCC include path to suit your installation. for search in binary_search_text_file linear_search_text_file boost_binary_search_text_file do echo "Testing $search ..." g++ -I /opt/local/include -O2 $search.cpp -o $search test_correctness $search test_performance $search echo done echo "Tests complete"