Skip to content

Commit 72dcdc9

Browse files
author
Jerjou Cheng
committed
Coerce number types before comparison
1 parent 4b7201c commit 72dcdc9

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

language/sentiment/sentiment_analysis_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@
1818
def test_pos(resource, capsys):
1919
main(resource('pos.txt'))
2020
out, err = capsys.readouterr()
21-
polarity = re.search('polarity of (.+?) with', out)
22-
magnitude = re.search('magnitude of (.+?)', out)
21+
polarity = float(re.search('polarity of (.+?) with', out).group(1))
22+
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
2323
assert polarity * magnitude > 0
2424

2525

2626
def test_neg(resource, capsys):
2727
main(resource('neg.txt'))
2828
out, err = capsys.readouterr()
29-
polarity = re.search('polarity of (.+?) with', out)
30-
magnitude = re.search('magnitude of (.+?)', out)
29+
polarity = float(re.search('polarity of (.+?) with', out).group(1))
30+
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
3131
assert polarity * magnitude < 0
3232

3333

3434
def test_mixed(resource, capsys):
3535
main(resource('mixed.txt'))
3636
out, err = capsys.readouterr()
37-
polarity = re.search('polarity of (.+?) with', out)
38-
assert polarity <= 0.3 is True
39-
assert polarity >= -0.3 is True
37+
polarity = float(re.search('polarity of (.+?) with', out).group(1))
38+
assert polarity <= 0.3
39+
assert polarity >= -0.3
4040

4141

4242
def test_neutral(resource, capsys):
4343
main(resource('neutral.txt'))
4444
out, err = capsys.readouterr()
45-
magnitude = re.search('magnitude of (.+?)', out)
46-
assert magnitude <= 2.0 is True
45+
magnitude = float(re.search('magnitude of (.+?)', out).group(1))
46+
assert magnitude <= 2.0

0 commit comments

Comments
 (0)