def inequality_test(): a = testhelper.get_symbol_as_handwriting(97705) b = testhelper.get_symbol_as_handwriting(292934) nose.tools.assert_equal(a == b, False) c = [] nose.tools.assert_equal(a == c, False) nose.tools.assert_equal(a != c, True)
def test_inequality(): a = testhelper.get_symbol_as_handwriting(97705) b = testhelper.get_symbol_as_handwriting(292934) assert a != b c = [] assert not (a == c) assert a != c
def training_set_multiplication_test(): """Test the create_ffiles.training_set_multiplication method.""" sample = th.get_symbol_as_handwriting(292934) training_set = [{'id': 1337, 'is_in_testset': 0, 'formula_id': 42, 'handwriting': sample, 'formula_in_latex': 'B'}] mult_queue = [data_multiplication.Multiply()] create_ffiles.training_set_multiplication(training_set, mult_queue)
def test_training_set_multiplication(): """Test the create_ffiles.training_set_multiplication method.""" sample = th.get_symbol_as_handwriting(292934) training_set = [{ "id": 1337, "is_in_testset": 0, "formula_id": 42, "handwriting": sample, "formula_in_latex": "B", }] mult_queue = [data_multiplication.Multiply()] create_ffiles.training_set_multiplication(training_set, mult_queue)
def training_set_multiplication_test(): """Test the create_ffiles.training_set_multiplication method.""" sample = th.get_symbol_as_handwriting(292934) training_set = [{ 'id': 1337, 'is_in_testset': 0, 'formula_id': 42, 'handwriting': sample, 'formula_in_latex': 'B' }] mult_queue = [data_multiplication.Multiply()] create_ffiles.training_set_multiplication(training_set, mult_queue)
def constant_point_coordinates_test(): """Test features.ConstantPointCoordinates.""" f = features.ConstantPointCoordinates(strokes=0, points_per_stroke=2, pen_down=False) g = features.ConstantPointCoordinates(strokes=0, points_per_stroke=200, pen_down=False) recording = testhelper.get_symbol_as_handwriting(292934) f._features_without_strokes(recording) g._features_without_strokes(recording) space_evenly = preprocessing.SpaceEvenly() space_evenly(recording) f._features_without_strokes(recording)
def prepare_dataset_test(): """Test create_ffiles.prepare_dataset.""" dataset = [] for i in range(200): dataset.append({'handwriting': th.get_symbol_as_handwriting(97705), 'formula_id': 42}) # dataset[-1]['handwriting'].formula_id = 42 formula_id2index = {} formula_id2index[42] = 1 feature_list = [features.StrokeCount()] is_traindata = False create_ffiles.prepare_dataset(dataset, formula_id2index, feature_list, is_traindata)
def test_prepare_dataset(): """Test create_ffiles.prepare_dataset.""" dataset = [] for i in range(200): dataset.append({ "handwriting": th.get_symbol_as_handwriting(97705), "formula_id": 42 }) # dataset[-1]['handwriting'].formula_id = 42 formula_id2index = {} formula_id2index[42] = 1 feature_list = [features.StrokeCount()] is_traindata = False create_ffiles.prepare_dataset(dataset, formula_id2index, feature_list, is_traindata)
def test_simple_execution_test(): algorithms = [ preprocessing.RemoveDuplicateTime(), preprocessing.RemoveDots(), preprocessing.SpaceEvenly(), preprocessing.SpaceEvenlyPerStroke(), preprocessing.DouglasPeucker(), preprocessing.StrokeConnect(), preprocessing.DotReduction(), preprocessing.WildPointFilter(), preprocessing.WeightedAverageSmoothing(), ] for algorithm in algorithms: a = testhelper.get_symbol_as_handwriting(292934) algorithm(a)
def simple_execution_test(): algorithms = [ features.ConstantPointCoordinates(), features.ConstantPointCoordinates(strokes=0), features.FirstNPoints(), # features.Bitmap(), features.Ink(), features.AspectRatio(), features.Width(), features.Time(), features.CenterOfMass(), features.StrokeCenter(), features.StrokeCenter(8), features.StrokeIntersections(), features.ReCurvature() ] for algorithm in algorithms: recording = testhelper.get_symbol_as_handwriting(292934) algorithm(recording)
def stringification_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(str(a), "HandwrittenData(raw_data_id=None)")
def stroke_intersections_test(): f = features.StrokeIntersections(strokes=4) recording = testhelper.get_symbol_as_handwriting(293035) x = f(recording) nose.tools.assert_equal(x, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0])
def test_equality(): _ = testhelper.get_symbol_as_handwriting(97705)
def recurvature_test(): """A 'o' ends in itself. The re-curvature is therefore 0.""" recording = testhelper.get_symbol_as_handwriting(293036) feature = features.ReCurvature(1) feature(recording)
def height_test(): feature_list = [features.Height()] a = testhelper.get_symbol_as_handwriting(97705) # TODO: Check if this is correct nose.tools.assert_equal(a.feature_extraction(feature_list), [263.0])
def show_test(): a = testhelper.get_symbol_as_handwriting(97705) with mock.patch('matplotlib.pyplot.show', return_value='yes'): a.show()
def center_of_mass_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a.get_center_of_mass(), (229.21875, 207.265625))
def test_show(): a = testhelper.get_symbol_as_handwriting(97705) with mock.patch("matplotlib.pyplot.show", return_value="yes"): a.show()
def test_time(): a = testhelper.get_symbol_as_handwriting(97705) assert a.get_time() == 1876
def test_area(): a = testhelper.get_symbol_as_handwriting(97705) # TODO: Is this really correct? assert a.get_area() == 49368.0
def test_stringification(): a = testhelper.get_symbol_as_handwriting(97705) assert str(a) == "HandwrittenData(raw_data_id=None)"
def test_count_single_dots(): a = testhelper.get_symbol_as_handwriting(97705) a.set_pointlist([[{"x": 12, "y": 42, "time": 100}]]) assert a.count_single_dots() == 1
def area_test(): a = testhelper.get_symbol_as_handwriting(97705) # TODO: Is this really correct? nose.tools.assert_equal(a.get_area(), 49368.0)
def time_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a.get_time(), 1876)
def test_set_pointlist(): a = testhelper.get_symbol_as_handwriting(97705) a.set_pointlist([[]]) assert a.get_pointlist() == [[]]
def rotate_test(): recording = testhelper.get_symbol_as_handwriting(292934) rotation = data_multiplication.Rotate(minimum=-3, maximum=3, num=3) new_recordings = rotation(recording) # TODO: Not only compare lengths of lists but actual contents. nose.tools.assert_equal(len(new_recordings), 3)
def stroke_count_test(): feature_list = [features.StrokeCount()] a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a.feature_extraction(feature_list), [1])
def get_sorted_pointlist_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a.get_sorted_pointlist(), [[ {'y': 223.125, 'x': 328.5, 'time': 1377173554837}, {'y': 225.125, 'x': 326.5, 'time': 1377173554868}, {'y': 226.125, 'x': 322.5, 'time': 1377173554876}, {'y': 229.125, 'x': 319.5, 'time': 1377173554885}, {'y': 231.125, 'x': 315.5, 'time': 1377173554895}, {'y': 237.125, 'x': 304.5, 'time': 1377173554912}, {'y': 245.125, 'x': 291.5, 'time': 1377173554928}, {'y': 253.125, 'x': 274.5, 'time': 1377173554945}, {'y': 261.125, 'x': 256.5, 'time': 1377173554964}, {'y': 267.125, 'x': 243.5, 'time': 1377173554978}, {'y': 276.125, 'x': 222.5, 'time': 1377173554995}, {'y': 279.125, 'x': 211.5, 'time': 1377173555012}, {'y': 280.125, 'x': 204.5, 'time': 1377173555031}, {'y': 281.125, 'x': 196.5, 'time': 1377173555045}, {'y': 281.125, 'x': 183.5, 'time': 1377173555061}, {'y': 281.125, 'x': 172.5, 'time': 1377173555078}, {'y': 280.125, 'x': 163.5, 'time': 1377173555095}, {'y': 274.125, 'x': 149.5, 'time': 1377173555128}, {'y': 270.125, 'x': 144.5, 'time': 1377173555147}, {'y': 266.125, 'x': 142.5, 'time': 1377173555180}, {'y': 258.125, 'x': 142.5, 'time': 1377173555216}, {'y': 226.125, 'x': 143.5, 'time': 1377173555264}, {'y': 212.125, 'x': 148.5, 'time': 1377173555281}, {'y': 204.125, 'x': 156.5, 'time': 1377173555296}, {'y': 182.125, 'x': 176.5, 'time': 1377173555330}, {'y': 167.125, 'x': 189.5, 'time': 1377173555363}, {'y': 152.125, 'x': 201.5, 'time': 1377173555397}, {'y': 148.125, 'x': 206.5, 'time': 1377173555417}, {'y': 132.125, 'x': 223.5, 'time': 1377173555463}, {'y': 121.125, 'x': 231.5, 'time': 1377173555496}, {'y': 106.125, 'x': 241.5, 'time': 1377173555530}, {'y': 94.125, 'x': 243.5, 'time': 1377173555563}, {'y': 81.125, 'x': 241.5, 'time': 1377173555596}, {'y': 75.125, 'x': 236.5, 'time': 1377173555630}, {'y': 62.125, 'x': 222.5, 'time': 1377173555663}, {'y': 54.125, 'x': 208.5, 'time': 1377173555696}, {'y': 50.125, 'x': 198.5, 'time': 1377173555730}, {'y': 50.125, 'x': 182.5, 'time': 1377173555763}, {'y': 50.125, 'x': 174.5, 'time': 1377173555795}, {'y': 57.125, 'x': 168.5, 'time': 1377173555830}, {'y': 67.125, 'x': 166.5, 'time': 1377173555862}, {'y': 80.125, 'x': 166.5, 'time': 1377173555896}, {'y': 102.125, 'x': 173.5, 'time': 1377173555930}, {'y': 130.125, 'x': 184.5, 'time': 1377173555962}, {'y': 157.125, 'x': 195.5, 'time': 1377173555996}, {'y': 176.125, 'x': 207.5, 'time': 1377173556030}, {'y': 194.125, 'x': 217.5, 'time': 1377173556061}, {'y': 207.125, 'x': 225.5, 'time': 1377173556094}, {'y': 215.125, 'x': 231.5, 'time': 1377173556115}, {'y': 229.125, 'x': 239.5, 'time': 1377173556147}, {'y': 242.125, 'x': 246.5, 'time': 1377173556180}, {'y': 259.125, 'x': 258.5, 'time': 1377173556216}, {'y': 274.125, 'x': 269.5, 'time': 1377173556247}, {'y': 282.125, 'x': 275.5, 'time': 1377173556280}, {'y': 290.125, 'x': 280.5, 'time': 1377173556315}, {'y': 292.125, 'x': 281.5, 'time': 1377173556349}, {'y': 292.125, 'x': 282.5, 'time': 1377173556395}, {'y': 293.125, 'x': 283.5, 'time': 1377173556499}, {'y': 295.125, 'x': 286.5, 'time': 1377173556652}, {'y': 300.125, 'x': 290.5, 'time': 1377173556660}, {'y': 304.125, 'x': 294.5, 'time': 1377173556668}, {'y': 307.125, 'x': 297.5, 'time': 1377173556682}, {'y': 311.125, 'x': 300.5, 'time': 1377173556697}, {'y': 313.125, 'x': 302.5, 'time': 1377173556713}] ])
def test_center_of_mass(): a = testhelper.get_symbol_as_handwriting(97705) assert a.get_center_of_mass() == (229.21875, 207.265625)
def equality_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a == a, True)
def set_pointlist_test(): a = testhelper.get_symbol_as_handwriting(97705) a.set_pointlist([[]]) nose.tools.assert_equal(a.get_pointlist(), [[]])
def get_sorted_pointlist_test(): a = testhelper.get_symbol_as_handwriting(97705) nose.tools.assert_equal(a.get_sorted_pointlist(), [[{ 'y': 223.125, 'x': 328.5, 'time': 1377173554837 }, { 'y': 225.125, 'x': 326.5, 'time': 1377173554868 }, { 'y': 226.125, 'x': 322.5, 'time': 1377173554876 }, { 'y': 229.125, 'x': 319.5, 'time': 1377173554885 }, { 'y': 231.125, 'x': 315.5, 'time': 1377173554895 }, { 'y': 237.125, 'x': 304.5, 'time': 1377173554912 }, { 'y': 245.125, 'x': 291.5, 'time': 1377173554928 }, { 'y': 253.125, 'x': 274.5, 'time': 1377173554945 }, { 'y': 261.125, 'x': 256.5, 'time': 1377173554964 }, { 'y': 267.125, 'x': 243.5, 'time': 1377173554978 }, { 'y': 276.125, 'x': 222.5, 'time': 1377173554995 }, { 'y': 279.125, 'x': 211.5, 'time': 1377173555012 }, { 'y': 280.125, 'x': 204.5, 'time': 1377173555031 }, { 'y': 281.125, 'x': 196.5, 'time': 1377173555045 }, { 'y': 281.125, 'x': 183.5, 'time': 1377173555061 }, { 'y': 281.125, 'x': 172.5, 'time': 1377173555078 }, { 'y': 280.125, 'x': 163.5, 'time': 1377173555095 }, { 'y': 274.125, 'x': 149.5, 'time': 1377173555128 }, { 'y': 270.125, 'x': 144.5, 'time': 1377173555147 }, { 'y': 266.125, 'x': 142.5, 'time': 1377173555180 }, { 'y': 258.125, 'x': 142.5, 'time': 1377173555216 }, { 'y': 226.125, 'x': 143.5, 'time': 1377173555264 }, { 'y': 212.125, 'x': 148.5, 'time': 1377173555281 }, { 'y': 204.125, 'x': 156.5, 'time': 1377173555296 }, { 'y': 182.125, 'x': 176.5, 'time': 1377173555330 }, { 'y': 167.125, 'x': 189.5, 'time': 1377173555363 }, { 'y': 152.125, 'x': 201.5, 'time': 1377173555397 }, { 'y': 148.125, 'x': 206.5, 'time': 1377173555417 }, { 'y': 132.125, 'x': 223.5, 'time': 1377173555463 }, { 'y': 121.125, 'x': 231.5, 'time': 1377173555496 }, { 'y': 106.125, 'x': 241.5, 'time': 1377173555530 }, { 'y': 94.125, 'x': 243.5, 'time': 1377173555563 }, { 'y': 81.125, 'x': 241.5, 'time': 1377173555596 }, { 'y': 75.125, 'x': 236.5, 'time': 1377173555630 }, { 'y': 62.125, 'x': 222.5, 'time': 1377173555663 }, { 'y': 54.125, 'x': 208.5, 'time': 1377173555696 }, { 'y': 50.125, 'x': 198.5, 'time': 1377173555730 }, { 'y': 50.125, 'x': 182.5, 'time': 1377173555763 }, { 'y': 50.125, 'x': 174.5, 'time': 1377173555795 }, { 'y': 57.125, 'x': 168.5, 'time': 1377173555830 }, { 'y': 67.125, 'x': 166.5, 'time': 1377173555862 }, { 'y': 80.125, 'x': 166.5, 'time': 1377173555896 }, { 'y': 102.125, 'x': 173.5, 'time': 1377173555930 }, { 'y': 130.125, 'x': 184.5, 'time': 1377173555962 }, { 'y': 157.125, 'x': 195.5, 'time': 1377173555996 }, { 'y': 176.125, 'x': 207.5, 'time': 1377173556030 }, { 'y': 194.125, 'x': 217.5, 'time': 1377173556061 }, { 'y': 207.125, 'x': 225.5, 'time': 1377173556094 }, { 'y': 215.125, 'x': 231.5, 'time': 1377173556115 }, { 'y': 229.125, 'x': 239.5, 'time': 1377173556147 }, { 'y': 242.125, 'x': 246.5, 'time': 1377173556180 }, { 'y': 259.125, 'x': 258.5, 'time': 1377173556216 }, { 'y': 274.125, 'x': 269.5, 'time': 1377173556247 }, { 'y': 282.125, 'x': 275.5, 'time': 1377173556280 }, { 'y': 290.125, 'x': 280.5, 'time': 1377173556315 }, { 'y': 292.125, 'x': 281.5, 'time': 1377173556349 }, { 'y': 292.125, 'x': 282.5, 'time': 1377173556395 }, { 'y': 293.125, 'x': 283.5, 'time': 1377173556499 }, { 'y': 295.125, 'x': 286.5, 'time': 1377173556652 }, { 'y': 300.125, 'x': 290.5, 'time': 1377173556660 }, { 'y': 304.125, 'x': 294.5, 'time': 1377173556668 }, { 'y': 307.125, 'x': 297.5, 'time': 1377173556682 }, { 'y': 311.125, 'x': 300.5, 'time': 1377173556697 }, { 'y': 313.125, 'x': 302.5, 'time': 1377173556713 }]])
def count_single_dots_test(): a = testhelper.get_symbol_as_handwriting(97705) a.set_pointlist([[{'x': 12, 'y': 42, 'time': 100}]]) nose.tools.assert_equal(a.count_single_dots(), 1)