"""
Nose tests for acp_times based on 
rules from here https://rusa.org/pages/acp-brevet-control-times-calculator
"""

import arrow
from acp_times import open_time, close_time

brevets = [200, 300, 400, 600, 1000]
speeds = [ (200,15,34), (400,15,32), (600,15,30),
          (1000,11.428,28), (1300,13.333,26) ]

# Do one test for each brevet
test_start_arrow = arrow.get('2021-05-01 12:00:00', 'YYYY-MM-DD HH:mm:ss')
test_controls = [ [20, 75, 150, 210], [30, 120, 240, 305], [40, 140, 275, 402], 
				[50, 220, 425, 607], [60, 300, 675, 1003] ]

expected_open = ["2021-05-01T12:35", "2021-05-01T14:12", "2021-05-01T16:25", "2021-05-01T17:53", 
				"2021-05-01T12:53", "2021-05-01T15:32","2021-05-01T19:08","2021-05-01T21:00",
				"2021-05-01T13:11","2021-05-01T16:07","2021-05-01T20:14", "2021-05-02T00:08",											
				"2021-05-01T13:28","2021-05-01T18:30","2021-05-02T00:58","2021-05-02T06:48",							
				"2021-05-01T13:46", "2021-05-01T21:00", "2021-05-02T09:29", "2021-05-02T21:05"]

expected_close = ["2021-05-01T14:00", "2021-05-01T17:00", "2021-05-01T22:00", "2021-05-02T01:30",
				  "2021-05-01T14:30", "2021-05-01T20:00","2021-05-02T04:00","2021-05-02T08:00",
				  "2021-05-01T15:00","2021-05-01T21:20","2021-05-02T06:20","2021-05-02T15:00",
				  "2021-05-01T15:30","2021-05-02T02:40","2021-05-02T16:20","2021-05-03T04:00",			  			
				  "2021-05-01T16:00","2021-05-02T08:00", "2021-05-03T10:34", "2021-05-04T15:00"	]


# def test_control_exceeds_brevet():
#    test_control_dist = 500			# control distance > brevet
#    test_brevet_dist = brevets[1]	# 200 km brevet
#    result = open_time(test_control_dist, test_brevet_dist, test_start_arrow)

#    assert result == False

   
# Each function tests 20 different cases (20 for open times, 20 for closing times)

def test_open_times():
	h = 0
	j = 0
	for brev in brevets:
		print("\nbrevet distance = " + str(brev))
		for dist in test_controls[h]:
			print("control distance = " + str(dist))
			result = open_time(dist, brev, test_start_arrow)
			# print("result = " + result.format('YYYY-MM-DDTHH:mm'))
			# print("expected_open[{}] = {}".format(j, expected_open[j]))
			# print("\n")
			assert (result.format('YYYY-MM-DDTHH:mm') == expected_open[j])
			j += 1
		h += 1
  	

def test_close_times():
	h = 0
	j = 0
	for brev in brevets:
		print("\nbrevet distance = " + str(brev))
		for dist in test_controls[h]:
			print("control distance = " + str(dist))
			result = close_time(dist, brev, test_start_arrow)
			# print("result = " + result.format('YYYY-MM-DDTHH:mm'))
			# print("expected_close[{}] = {}".format(j, expected_close[j]))
			# print("\n")
			assert (result.format('YYYY-MM-DDTHH:mm') == expected_close[j])
			j += 1
		h += 1