-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq_testing.py
More file actions
60 lines (51 loc) · 1.93 KB
/
seq_testing.py
File metadata and controls
60 lines (51 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Provides the main file from which testing is run
"""
import numpy as np
from game_modes import *
from timeit import default_timer as timer
NUM_GAMES = 2000 # Number of games each algorithm is tested over
NUM_SUITS = 4 # Number of suits each game is played with
VAL_RANGE = 13 # Defines the value range over which each game is played
timed = 1 # Turn on to measure time tests take
"""
Finds the mean, median, and standard deviation of a NumPy array and return them
in a list, in that order
"""
def get_data(arr):
data = []
data.append(np.mean(arr))
data.append(np.median(arr))
data.append(np.std(arr))
return data
"""
Prints mean, median, and standard deviation to standard output
"""
def print_data(data):
print("Mean = {:.5f}".format(data[0]))
print("Median = {:.0f}".format(data[1]))
print("Standard deviation = {:.5f}\n".format(data[2]))
def main():
print("\nOver {} games played sequentially with {} suits and max value of {}:\n".format(NUM_GAMES, NUM_SUITS, VAL_RANGE))
# Test simple binary seerch algorithm
bs_points = np.zeros(NUM_GAMES)
if timed: bs_start = timer()
for i in range(NUM_GAMES):
bs_points[i] = binarySearch(NUM_SUITS, VAL_RANGE)
if timed: bs_end = timer()
bs_data = get_data(bs_points)
print("Simple binary search results:")
print_data(bs_data)
if timed: print("time elapsed for testing: {:.8f} seconds\n".format(bs_end - bs_start))
# Test optimal algorithm
opt_points = np.zeros(NUM_GAMES)
if timed: opt_start = timer()
for i in range(NUM_GAMES):
opt_points[i] = Opt(NUM_SUITS, VAL_RANGE)
if timed: opt_end = timer()
opt_data = get_data(opt_points)
print("Optimal algorithm results:")
print_data(opt_data)
if timed: print("time elapsed for testing: {:.8f} seconds\n".format(opt_end - opt_start))
if __name__ == "__main__":
main()