@dj2638/

MathGear

Python

No description

fork
loading
Files
  • main.py
  • config.py
  • triangles.py
main.py
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
import unittest
from triangles import LawOfCosines
import config

testing = False


class LawOfCosinesTestCase(unittest.TestCase):
	def setUp(self):
		self.triangle = {"a": 50, "b": 60, "c": 20,
						 "A": 51.3178, "B": 110.4873, "C": 18.1949}

	def test_solve_sas(self):
		result = LawOfCosines.sas(self.triangle["a"], self.triangle["C"], self.triangle["b"])
		result = round(result, config.defaults["decimal_precision"])
		self.assertEqual(result, self.triangle["c"])

	def test_solve_sss(self):
		results = LawOfCosines.sss(self.triangle["a"], self.triangle["b"], self.triangle["c"])
		for r in results:
			self.assertEqual(round(results[r], config.defaults["decimal_precision"]), self.triangle[r])

def main():
	if testing:
		unittest.main()
	else:
		done = False
		while not done:
			case = str(input("'sss' or 'sas'\n>>> "))
			if case == "sss":
				values = str(input("input values of a,b,c\n>>> "))
				values = values.split()
				for i in range(3):
					values[i] = float(values[i])
				r = LawOfCosines.sss(values[0], values[1], values[2])
				for i in r:
					print("{label} = {value}".format(label=i, value=r[i]))

			elif case == "sas":
				values = str(input("input values of a,C,b\n>>> "))
				values = values.split()
				for i in range(3):
					values[i] = float(values[i])
				print("c = {value}".format(value=LawOfCosines.sas(values[0], values[1], values[2])))
			
			elif case == "done":
				done = True

if __name__ == "__main__":
	main()