FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
code-guild/code-guild/python/testing/unit testers.py at master · grantholly/code-guild · GitHub
grantholly
code-guild
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
code-guild
/
code-guild
/
python
/
testing
/
unit testers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (45 loc) · 1.91 KB
Breadcrumbs
code-guild
/
code-guild
/
python
/
testing
/
unit testers.py
Copy path
File metadata and controls
66 lines (45 loc) · 1.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__author__
=
'grant'
#pip install pytest
#pip install nose (nosetests)
from
file_to_test
import
functions_to_test
from
unittest
import
TestCase
def
test_sets_with_intersection
():
assert
(
improved_similarity
([
'a'
,
'b'
], [
'b'
,
'c'
,
'd'
]))
==
0.25
def
test_sets_with_non_distinct_elements
():
assert
(
improved_similarity
([
'a'
,
'a'
], [
'a'
,
'b'
]))
==
0.5
def
test_sets_with_empty_sets
():
assert
(
improved_similarity
([], []))
==
0.0
def
test_sets_with_no_intersection
():
assert
(
improved_similarity
([
'a'
,
'b'
], [
'c'
,
'd'
,
'e'
]))
==
0.0
"""
pytest (http://pytest.org/latest/)
looks for any function with the prefix of test_*
and runs it as a test and exports the test results
run your test with >>>py.test then your file.py
$ py.test test_assert1.py
=========================== test session starts ============================
platform linux -- Python 3.4.0 -- py-1.4.23 -- pytest-2.6.1
collected 1 items
test_assert1.py F
================================= FAILURES =================================
______________________________ test_function _______________________________
def test_function():
> assert f() == 4
E assert 3 == 4
E + where 3 = f()
test_assert1.py:5: AssertionError
========================= 1 failed in 0.01 seconds =========================
"""
class
TestImprovedSimilarity
(
TestCase
):
def
test_sets_with_intersection
():
my_test
=
improved_similarity
([
'a'
,
'b'
], [
'b'
,
'c'
,
'd'
])
self
.
assertEqual
(
my_test
,
0.25
)
def
test_sets_with_non_distinct_elements
():
my_test
=
test_sets_with_non_distinct_elements
([
'a'
,
'a'
], [
'a'
,
'b'
])
self
.
assertEqual
(
my_test
,
0.5
)
def
test_sets_with_empty_sets
():
my_test
=
improved_similarity
([], [])
self
.
assertEqual
(
my_test
,
0.0
)
def
test_sets_with_no_intersection
():
my_test
=
test_sets_with_no_intersection
([
'a'
,
'b'
], [
'c'
,
'd'
,
'e'
])
self
.
assertEqual
(
my_test
,
0.0
)
Back
|
FazBrowse Home
|
New Git URL