26 lines
1.4 KiB
Python
26 lines
1.4 KiB
Python
import unittest
|
|
import numpy as np
|
|
from scipy.sparse import csr_matrix
|
|
from phase2_gate_math import monotone_projection,quantize_lower_tie,birth_platforms
|
|
|
|
|
|
class GateMathTests(unittest.TestCase):
|
|
def test_perfect_order(self):
|
|
r,_=monotone_projection([1,2,3],[2,4,7],[1,1,1]);self.assertEqual(r['total_SSE'],0)
|
|
def test_all_ties_are_within_group_error(self):
|
|
r,z=monotone_projection([1,1,1],[1,2,5],[1,2,1]);self.assertEqual(r['between_order_SSE'],0)
|
|
self.assertAlmostEqual(r['within_tie_SSE'],9.);self.assertAlmostEqual(z['fitted'][0],2.5)
|
|
def test_two_point_reversal(self):
|
|
r,z=monotone_projection([0,1],[3,1],[1,3]);self.assertEqual(r['within_tie_SSE'],0)
|
|
self.assertAlmostEqual(r['between_order_SSE'],3.);np.testing.assert_array_equal(z['fitted'],[1.5,1.5])
|
|
def test_midpoint_rounds_lower_including_shifted_origin(self):
|
|
np.testing.assert_array_equal(quantize_lower_tie(np.array([.0005,.0015]),.001,0),[0.,.001])
|
|
self.assertEqual(float(quantize_lower_tie(np.array([0.]),.001,.0005)[0]),-.0005)
|
|
def test_births_preserve_disconnected_equal_maxima(self):
|
|
a=csr_matrix((np.ones(4),([0,1,1,2],[1,0,2,1])),shape=(3,3));x=np.c_[np.arange(3),np.zeros((3,2))]
|
|
r=birth_platforms(np.array([2,1,2]),np.ones(3),np.arange(10,13),x,a)
|
|
self.assertEqual([v['birth_min_raw_id'] for v in r],[10,12])
|
|
|
|
|
|
if __name__=='__main__':unittest.main()
|