import unittest
from fractions import Fraction
from matrix_decisions import break_even, surplus, flow, learning_outcomes, claim_status
class DecisionFixtures(unittest.TestCase):
 def test_base_break_even(self):self.assertEqual(break_even('12000','500','300'),60)
 def test_discount(self):self.assertEqual(break_even('12000','450','300'),80)
 def test_below(self):self.assertEqual(surplus(59,12000,500,300),-200)
 def test_at(self):self.assertEqual(surplus(60,12000,500,300),0)
 def test_above(self):self.assertEqual(surplus(61,12000,500,300),200)
 def test_indivisible_rounding(self):self.assertEqual(break_even('10','4','1'),4)
 def test_exact_decimal(self):self.assertEqual(break_even('0.3','0.2','0.1'),3)
 def test_zero_fixed(self):self.assertEqual(break_even(0,2,1),0)
 def test_zero_contribution(self):
  with self.assertRaises(ValueError):break_even(10,2,2)
 def test_negative_contribution(self):
  with self.assertRaises(ValueError):break_even(10,1,2)
 def test_nonfinite(self):
  with self.assertRaises(ValueError):break_even('nan',2,1)
 def test_negative_amount(self):
  with self.assertRaises(ValueError):break_even(-1,2,1)
 def test_boolean_count(self):
  with self.assertRaises(ValueError):surplus(True,10,3,1)
 def test_fractional_count(self):
  with self.assertRaises(ValueError):flow(1,3,1.5,4)
 def test_daily_flow(self):self.assertEqual(flow(10,30,25,30),dict(closing=15,utilization=Fraction(5,6),same_day_shortfall=10))
 def test_impossible_completions(self):
  with self.assertRaises(ValueError):flow(0,1,2,3)
 def test_over_capacity(self):
  with self.assertRaises(ValueError):flow(10,10,12,10)
 def test_zero_capacity(self):
  with self.assertRaises(ValueError):flow(1,2,0,0)
 def test_learning_denominators(self):self.assertEqual(learning_outcomes(12,8,6),dict(submitted=Fraction(2,3),success_among_submitters=Fraction(3,4),observed_success_among_attendees=Fraction(1,2),unknown_outcomes=4))
 def test_unknown_not_failure(self):self.assertEqual(learning_outcomes(12,8,8)['unknown_outcomes'],4)
 def test_impossible_successes(self):
  with self.assertRaises(ValueError):learning_outcomes(12,8,9)
 def test_missing_denominator(self):
  with self.assertRaises(ValueError):learning_outcomes(12,0,0)
 def test_supported(self):self.assertEqual(claim_status({'days':'14'},'days','14'),'supported')
 def test_conflicting(self):self.assertEqual(claim_status({'days':'14'},'days','30'),'conflicting')
 def test_unsupported(self):self.assertEqual(claim_status({'days':'14'},'collection','free'),'unsupported')
 def test_exact_not_semantic(self):self.assertEqual(claim_status({'days':'14'},'days','fourteen'),'conflicting')
 def test_missing_claim(self):
  with self.assertRaises(ValueError):claim_status({'days':'14'},'days','')
 def test_bad_policy(self):
  with self.assertRaises(ValueError):claim_status({'days':14},'days','14')
if __name__=='__main__':unittest.main()
