@@ -0,0 +1,2222 @@
+import json%0Aimport unittest%0A%0Afrom embedded_jubatus import Anomaly%0Afrom jubatus.anomaly.types import IdWithScore%0Afrom jubatus.common import Datum%0A%0A%0ACONFIG = %7B%0A    'method': 'lof',%0A    'parameter': %7B%0A        'nearest_neighbor_num': 3,%0A        'reverse_nearest_neighbor_num': 5,%0A        'method': 'lsh',%0A        'parameter': %7B%0A            'hash_num': 512,%0A        %7D%0A    %7D,%0A    'converter': %7B%0A        'num_filter_types': %7B%7D,%0A        'num_filter_rules': %5B%5D,%0A        'string_filter_types': %7B%7D,%0A        'string_filter_rules': %5B%5D,%0A        'num_types': %7B%7D,%0A        'num_rules': %5B%0A            %7B'key': '*', 'type': 'num'%7D%0A        %5D,%0A        'string_types': %7B%7D,%0A        'string_rules': %5B%0A            %7B'key': '*', 'type': 'space',%0A             'sample_weight': 'bin', 'global_weight': 'bin'%7D%0A        %5D%0A    %7D,%0A%7D%0A%0A%0Aclass TestAnomaly(unittest.TestCase):%0A    def test_invalid_configs(self):%0A        self.assertRaises(TypeError, Anomaly)%0A        self.assertRaises(ValueError, Anomaly, 'hoge')%0A        self.assertRaises(ValueError, Anomaly, %7B%7D)%0A        self.assertRaises(TypeError, Anomaly, %7B'method': 'hoge'%7D)%0A        self.assertRaises(RuntimeError, Anomaly,%0A                          %7B'method': 'hoge', 'converter': %7B%7D%7D)%0A        invalid_config = dict(CONFIG)%0A        invalid_config%5B'method'%5D = 'hoge'%0A        self.assertRaises(RuntimeError, Anomaly, invalid_config)%0A%0A    def test(self):%0A        x = Anomaly(CONFIG)%0A        self.assertEqual(float('inf'), x.add(Datum(%7B'x': 0.1%7D)).score)%0A        self.assertTrue(isinstance(x.add(Datum(%7B'x': 0.101%7D)), IdWithScore))%0A        x.add(Datum(%7B'x': 0.1001%7D))%0A        x.calc_score(Datum(%7B'x': 0.1001%7D))%0A        self.assertEqual(set(%5B'0', '1', '2'%5D), set(x.get_all_rows()))%0A%0A        model = x.dump()%0A        x.clear()%0A        self.assertEqual(%5B%5D, x.get_all_rows())%0A%0A        x = Anomaly(CONFIG)%0A        x.load(model)%0A        self.assertEqual(set(%5B'0', '1', '2'%5D), set(x.get_all_rows()))%0A        self.assertEqual(CONFIG, json.loads(x.get_config()))%0A%0A        p = x.add(Datum(%7B'x': 0.2%7D))%0A        self.assertEqual(set(%5B'0', '1', '2', '3'%5D), set(x.get_all_rows()))%0A        self.assertEqual(p.score, x.update(p.id, Datum(%7B'x': 0.2%7D)))%0A        self.assertEqual(p.score, x.overwrite(p.id, Datum(%7B'x': 0.2%7D)))%0A

add anomaly tests