forked from codewars/codewars-runner-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.yml
More file actions
135 lines (103 loc) · 4.65 KB
/
python.yml
File metadata and controls
135 lines (103 loc) · 4.65 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
cw-2:
algorithms:
initial: |-
# return the two oldest/oldest ages within the array of ages passed in.
# it should return the two ages as a sorted array, youngest age first
def two_oldest_ages(ages):
# TODO: complete
answer: |-
def two_oldest_ages(ages):
oldest = 0
next_oldest = 0;
for age in ages:
if age > oldest:
next_oldest = oldest
oldest = age
elif age > next_oldest:
next_oldest = age
return [next_oldest, oldest]
fixture: |-
# some example data
results1 = two_oldest_ages([1,5,87,45,8,8])
results2 = two_oldest_ages([6,5,83,5,3,18])
# NOTE: You can use Test or test, whichever you prefer.
# Use "describe" to label your test suite.
Test.describe("two_oldest_ages:")
# Use "it" to identify the conditions you are testing for
Test.it("should return the second oldest age first")
# using assert_equals will report the invalid values to the user
Test.assert_equals(results1[0], 45)
# using expect will just give a user a generic error message, unless you provide a message
Test.expect(results2[0] == 18, "Number is not the second oldest")
# its best practice to test for multiple groups of tests, using it calls.
Test.it("should return the oldest age last")
Test.assert_equals(results1[1], 87)
Test.expect(results2[1] == 83, "Number is not the oldest")
bug fixes:
initial: |-
def add(a, b):
a + b
answer: |-
def add(a, b):
return a + b
fixture: |-
# Use "describe" to define the test suite
test.describe('add method')
# Use "it" to indicate a condition you are testing for
test.it('should add both arguments and return')
# "assert_equals" will return information about what values were
# expect if the assertion fails. This can be very useful to other
# users trying to pass the kata.
test.assert_equals(add(1,2), 3)
# "expect" is a lower level assertion that will allow you to test
# anything. It just needs a boolean result. You should pass a message
# as the second parameter so that if the assertion fails the user
# will be giving some useful information.
test.expect(add(1,1) == 2, "add(1,1) should == 2")
refactoring:
initial: |-
# refactor this method into a Person class with its own greet method
def greet(you, me):
return "Hello {0}, my name is {1}".format(you, me)
answer: |-
class Person:
def __init__(self, name):
self.name = name
def greet(self, name):
return "Hello {0}, my name is {1}".format(name, self.name)
fixture: |-
# Use "describe" to define the test suite
test.describe('Person')
jack = Person('Jack')
# Use "it" to indicate a condition you are testing for
test.it('should have a name')
# "assert_equals" will return information about what values were
# expect if the assertion fails. This can be very useful to other
# users trying to pass the kata.
test.assert_equals(jack.name, "Jack")
test.it("should greet Jill")
test.assert_equals(jack.greet("Jill"), "Hello Jill, my name is Jack")
test.it("should greet other people as well")
# unlike "assert_equals", "expect" is a lower level assertion that
# takes a boolean to determine if it passes. If it fails it will
# output the message that you give it, or a generic one. It is a good
# idea to provide a custom error message to help users pass the kata
test.expect(jack.greet("Jane") == "Hello Jane, my name is Jack", "Jack apparently is only able to greet Jane")
reference:
initial: |-
# create an array called websites that has "codewars" as its only value
answer: |-
websites = ['codewars']
fixture: |-
# Use test.describe (or Test.describe) to describe your test suite
test.describe("websites")
# Use "it" calls to describe the specific test case
test.it("should have the value 'codewars' inside of it")
# assert equals will pass if both items equal each other (using ==). If
# the test fails, assert_equals will output a descriptive message indicating
# what the values were expected to be.
test.assert_equals(['codewars'], websites)
# you can also use the lower level test.expect. If you use test.expect directly then
# you should provide a custom error message, as the default one will be pretty useless
# to users trying to pass the kata.
test.expect(['codewars'] == websites, 'Array does not have correct value')