コード例 #1
0
def test_get_slicing(abc, abctwo):
    assert not abc[0:1]
    assert abc[0:1].__class__ == abc.__class__
    assert not abc[1:1]
    assert abc[1:3] == ExtremeCounter({'a': 1, 'b': 1, 'c': 1})
    assert len(abc[1:2]) == 3
    assert len(abc[:2]) == 3
    assert len(abc[1:]) == 3
    assert len(abc[:]) == 3

    assert len(abc[0:1:-1]) == 3
    assert len(abc[1:2:-1]) == 0
    assert len(abc[:2:-1]) == 0
    assert len(abc[1::-1]) == 0
    assert len(abc[::-1]) == 0

    assert not abctwo[0:1]
    assert abctwo[1:2] == ExtremeCounter({'f': 1, 'h': 1})
    assert len(abctwo[1:2]) == 2
    assert len(abctwo[2:]) == 7
    assert len(abctwo[:]) == 9

    assert len(abctwo[0:1:-1]) == 9
    assert len(abctwo[1:2:-1]) == 7
    assert len(abctwo[2::-1]) == 2
    assert len(abctwo[::-1]) == 0
コード例 #2
0
def test_variants(x):
    x_1 = x.pivot()
    assert x_1 == PivotCounter({1: ['?', 'a', 'c', 'e', 'g', 'k', 'o', 'r', 'w'], 2: ['h', 'n', 's', 't', 'y'], 3: ['i'], 4: [' ', '!']})
    assert x_1.unpivot() == ExtremeCounter({' ': 4, '!': 4, '?': 1, 'a': 1, 'c': 1, 'e': 1, 'g': 1, 'h': 2, 'i': 3, 'k': 1, 'n': 2, 'o': 1, 'r': 1, 's': 2, 't': 2, 'w': 1, 'y': 2})
    x_2 = x.pivot(CoolPivotCounter)
    assert x_2 == CoolPivotCounter({1: ['?', 'a', 'c', 'e', 'g', 'k', 'o', 'r', 'w'], 2: ['h', 'n', 's', 't', 'y'], 3: ['i'], 4: [' ', '!']})
    assert x_2.unpivot() == x
    assert isinstance(x_2.unpivot(), x.__class__)
    assert x_2.unpivot().__class__ == x.__class__
    assert x_1 == x_2
    assert x.transpose() == ExtremeCounter({1: 9, 2: 5, 3: 1, 4: 2})
コード例 #3
0
def x():
    return ExtremeCounter("yay? nice!! this thing works!!")
コード例 #4
0
def test_features(x):
    assert ExtremeCounter("countlib") == ExtremeCounter({'b': 1, 'c': 1, 'i': 1, 'l': 1, 'n': 1, 'o': 1, 't': 1, 'u': 1})
    assert x.most_common_counts(1) == [(' ', 4), ('!', 4)]
    assert x.most_common_counts(1, inverse=True) == [('a', 1), ('c', 1), ('e', 1), ('g', 1), ('k', 1), ('o', 1), ('w', 1), ('r', 1), ('?', 1)]
コード例 #5
0
def test_pivot():
    x = ExtremeCounter("yay? nice!! this thing works!")
    x.add("etsttseststttsetsetse ")
    assert x.transpose().pivot(PivotCounter) == PivotCounter({1: [5, 6, 9, 11], 2: [3], 3: [2], 8: [1]})
    x.__pivot__ = PivotCounter
    assert x.pivot() + x.pivot() == PivotCounter(
            {10: [' '], 12: ['e'], 18: ['s'], 22: ['t'],
              2: ['?', 'a', 'c', 'g', 'k', 'o', 'r', 'w'],
              4: ['h', 'n', 'y'], 6: ['!', 'i']})
    lol = ExtremeCounter("lollofant!!")
    troll = ExtremeCounter("trollofant")
    assert lol.pivot() - troll.pivot() == PivotCounter({1: ['l'], 2: ['!']})
    assert lol.pivot() + troll.pivot() == PivotCounter({1: ['r'], 2: ['!', 'a', 'f', 'n'], 3: ['t'], 4: ['o'], 5: ['l']})
コード例 #6
0
def abc():
    return ExtremeCounter("abc")
コード例 #7
0
def test__getitem__(abc, abctwo):
    assert ExtremeCounter()["x"] == 0
    assert abc["x"] == 0
    assert abctwo["b"] == 3

    assert abc["a"] == abc["b"] == abc["c"] == 1
コード例 #8
0
def abctwo():
    return ExtremeCounter("abcabbcccddeefgggggghiii")