Beispiel #1
0
    def test_headers_and_encoders(self):
        a = SparseWithMeta({
            'a': '1',
            'b': '2'
        }, {
            'aa': 'a',
            'bb': 'b'
        }, {
            'a': float,
            'b': str
        })

        self.assertEqual({'a': 1, 'b': '2'}, a)
        self.assertEqual(2, len(a))

        self.assertEqual(1, a['aa'])
        self.assertEqual('2', a['bb'])

        a['bb'] = 3
        self.assertEqual(3, a['b'])
        self.assertEqual(3, a['bb'])

        del a['bb']
        self.assertEqual(1, len(a))
        self.assertEqual({'a': 1}, a)
Beispiel #2
0
    def test_pop(self):
        a = SparseWithMeta({
            'a': '1',
            'b': '2'
        }, {
            'aa': 'a',
            'bb': 'b'
        }, {
            'a': float,
            'b': str
        })

        self.assertEqual(1, a.pop('a'))
        self.assertEqual('2', a.pop('b'))

        self.assertEqual({}, dict(a))
        self.assertEqual("{}", a.__repr__())
        self.assertEqual(0, len(a))
Beispiel #3
0
    def test_no_headers_no_encoders(self):
        a = SparseWithMeta({'a': 1, 'b': 2})

        self.assertEqual({'a': 1, 'b': 2}, a)
        self.assertEqual(2, len(a))

        a['b'] = 3
        self.assertEqual(3, a['b'])

        del a['b']
        self.assertEqual(1, len(a))
        self.assertEqual({'a': 1}, a)
Beispiel #4
0
    def test_sparse_meta_x_a(self):
        encoder = InteractionsEncoder(["x", "a"])
        interactions = encoder.encode(x=SparseWithMeta({
            "1": 1,
            "2": 2
        }),
                                      a={
                                          "1": 3,
                                          "2": 4
                                      })

        self.assertEqual(dict([("x1", 1), ("x2", 2), ("a1", 3), ("a2", 4)]),
                         interactions)
Beispiel #5
0
 def test_repr(self):
     self.assertEqual("{'a': 2}", SparseWithMeta({'a': 2}).__repr__())
Beispiel #6
0
 def test_str(self):
     self.assertEqual("{'a': 2}", str(SparseWithMeta({'a': 2})))