|
1 |
| -from sklearn.utils.testing import assert_equal, assert_not_equal |
2 |
| - |
3 | 1 | from skrules import Rule, replace_feature_name
|
4 | 2 |
|
5 | 3 |
|
6 | 4 | def test_rule():
|
7 |
| - assert_equal(Rule('a <= 10 and a <= 12'), |
8 |
| - Rule('a <= 10')) |
9 |
| - assert_equal(Rule('a <= 10 and a <= 12 and a > 3'), |
10 |
| - Rule('a > 3 and a <= 10')) |
| 5 | + assert Rule("a <= 10 and a <= 12") == Rule("a <= 10") |
| 6 | + assert Rule("a <= 10 and a <= 12 and a > 3") == Rule("a > 3 and a <= 10") |
11 | 7 |
|
12 |
| - assert_equal(Rule('a <= 10 and a <= 10 and a > 3'), |
13 |
| - Rule('a > 3 and a <= 10')) |
| 8 | + assert Rule("a <= 10 and a <= 10 and a > 3") == Rule("a > 3 and a <= 10") |
14 | 9 |
|
15 |
| - assert_equal(Rule('a <= 10 and a <= 12 and b > 3 and b > 6'), |
16 |
| - Rule('a <= 10 and b > 6')) |
| 10 | + assert Rule("a <= 10 and a <= 12 and b > 3 and b > 6") == Rule("a <= 10 and b > 6") |
17 | 11 |
|
18 |
| - assert_equal(len({Rule('a <= 2 and a <= 3'), |
19 |
| - Rule('a <= 2') |
20 |
| - }), 1) |
| 12 | + assert len({Rule("a <= 2 and a <= 3"), Rule("a <= 2")}) == 1 |
21 | 13 |
|
22 |
| - assert_equal(len({Rule('a > 2 and a > 3 and b <= 2 and b <= 3'), |
23 |
| - Rule('a > 3 and b <= 2') |
24 |
| - }), 1) |
| 14 | + assert ( |
| 15 | + len({Rule("a > 2 and a > 3 and b <= 2 and b <= 3"), Rule("a > 3 and b <= 2")}) |
| 16 | + == 1 |
| 17 | + ) |
25 | 18 |
|
26 |
| - assert_equal(len({Rule('a <= 3 and b <= 2'), |
27 |
| - Rule('b <= 2 and a <= 3') |
28 |
| - }), 1) |
| 19 | + assert len({Rule("a <= 3 and b <= 2"), Rule("b <= 2 and a <= 3")}) == 1 |
29 | 20 |
|
30 | 21 |
|
31 | 22 | def test_hash_rule():
|
32 |
| - assert_equal(len({ |
33 |
| - Rule('a <= 2 and a <= 3'), |
34 |
| - Rule('a <= 2') |
35 |
| - }), 1) |
36 |
| - assert_not_equal(len({ |
37 |
| - Rule('a <= 4 and a <= 3'), |
38 |
| - Rule('a <= 2') |
39 |
| - }), 1) |
| 23 | + assert len({Rule("a <= 2 and a <= 3"), Rule("a <= 2")}) == 1 |
| 24 | + assert len({Rule("a <= 4 and a <= 3"), Rule("a <= 2")}) != 1 |
40 | 25 |
|
41 | 26 |
|
42 | 27 | def test_str_rule():
|
43 |
| - rule = 'a <= 10.0 and b > 3.0' |
44 |
| - assert_equal(rule, str(Rule(rule))) |
| 28 | + rule = "a <= 10.0 and b > 3.0" |
| 29 | + assert rule == str(Rule(rule)) |
45 | 30 |
|
46 | 31 |
|
47 | 32 | def test_equals_rule():
|
48 | 33 | rule = "a == a"
|
49 |
| - assert_equal(rule, str(Rule(rule))) |
| 34 | + assert rule == str(Rule(rule)) |
50 | 35 |
|
51 | 36 | rule2 = "a == a and a == a"
|
52 |
| - assert_equal(rule, str(Rule(rule2))) |
| 37 | + assert rule == str(Rule(rule2)) |
53 | 38 |
|
54 | 39 | rule3 = "a < 3.0 and a == a"
|
55 |
| - assert_equal(rule3, str(Rule(rule3))) |
| 40 | + assert rule3 == str(Rule(rule3)) |
56 | 41 |
|
57 | 42 |
|
58 | 43 | def test_replace_feature_name():
|
59 | 44 | rule = "__C__0 <= 3 and __C__1 > 4"
|
60 | 45 | real_rule = "$b <= 3 and c(4) > 4"
|
61 |
| - replace_dict = { |
62 |
| - "__C__0": "$b", |
63 |
| - "__C__1": "c(4)" |
64 |
| - } |
65 |
| - assert_equal(replace_feature_name(rule, replace_dict=replace_dict), real_rule) |
| 46 | + replace_dict = {"__C__0": "$b", "__C__1": "c(4)"} |
| 47 | + assert replace_feature_name(rule, replace_dict=replace_dict) == real_rule |
| 48 | + |
0 commit comments