Skip to content

Commit dab6b0b

Browse files
committed
Static and Dynamic Testing Tasks
0 parents  commit dab6b0b

31 files changed

+137
-0
lines changed
610 KB
Loading
606 KB
Loading
629 KB
Loading
609 KB
Loading
Loading
618 KB
Loading
Loading
639 KB
Loading
Loading
640 KB
Loading
Loading
515 KB
Loading
Loading
822 KB
Loading
Loading
Loading
Loading
Loading
Loading
749 KB
Loading
Loading
Loading

Static_&_Dynamic_Testing.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## PDA Software Development
2+
#### Implementation and Testing Unit Level 8
3+
4+
##### Testing tasks
5+
6+
#### Task 1: Static Testing
7+
8+
Carry out static testing on testing_task_1.md in the part_1_docs folder .
9+
10+
Read through the code. Comment any errors you can see but do not correct them in this file.
11+
12+
(Remember you can use `#` to comment in Ruby code.)
13+
14+
15+
#### Task 2: Dynamic Testing
16+
17+
Carry out dynamic testing on card_game.py in the part_2_code folder.
18+
19+
Read through the code. Complete the test file and write a test for each function. Screenshot the test code and the tests failing Correct the errors you spotted in task A and screenshot the tests passing. Save screenshots in the same folder as the code.
20+
21+
### Submitting
22+
23+
24+
- If you haven't already, create a GitHub repo for this task. Once you have completed submit the GitHub link via Canvas.
25+
26+
You can also use screenshots of the tests, tests failing and the tests passing, you can use this evidence for week 5.

part_1_docs/testing_task_1.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### Testing task 1:
2+
3+
# Carry out static testing on the code below.
4+
# Comment on any errors that you see below.
5+
6+
Note that we are only looking for errors here.
7+
8+
**Not** any issues with, i.e.:
9+
Thinking that methods should be renamed or should be class level, or using string interpolation etc.
10+
11+
These aren't errors but rather standards that vary from developer to developer.
12+
13+
Only comment on errors that would stop the tests running.
14+
15+
```python
16+
17+
class CardGame:
18+
19+
# Class doesn't start with an def __init__(self): method.
20+
def check_for_ace(self, card):
21+
if card.value = 1: # possibly wrong should be card.value == 1:
22+
return True
23+
else # colon is missing
24+
return False
25+
26+
27+
28+
29+
30+
dif highest_card(self, card1 card2): # Spelling error in the word 'dif' should be 'def'.
31+
if card1.value > card2.value: # There is an indent error.
32+
return card # typo needs to be card1.
33+
else:
34+
return card2
35+
36+
37+
38+
# Indent is off here as well.
39+
def cards_total(self, cards):
40+
total # total does not have anything associated with it. Should be an = 0.
41+
for card in cards:
42+
total += card.value
43+
return "You have a total of" + total # return statement needs to be indented back.
44+
45+
```

part_2_code/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

part_2_code/run_tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import unittest
2+
from specs.card_game_tests import TestCardGame
3+
4+
if __name__ == "__main__":
5+
unittest.main()

part_2_code/specs/__init__.py

Whitespace-only changes.

part_2_code/specs/card_game_tests.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
from src.card import Card
3+
from src.card_game import CardGame
4+
5+
class TestCardGame(unittest.TestCase):
6+
def setUp(self):
7+
self.ace = Card('hearts', 1)
8+
self.card2 = Card('hearts', 5)
9+
self.card3 = Card('hearts', 6)
10+
self.deck_of_cards = [self.ace, self.card2, self.card3]
11+
self.card_game = CardGame()
12+
13+
def test_check_for_ace(self):
14+
self.assertTrue(self.card_game.check_for_ace(self.ace))
15+
self.assertFalse(self.card_game.check_for_ace(self.card2))
16+
17+
def test_highest_card(self):
18+
self.hightest_card = self.card_game.highest_card(self.card2, self.card3)
19+
self.assertEqual(self.hightest_card.value, 6)
20+
21+
self.hightest_card = self.card_game.highest_card(self.card3, self.card2)
22+
self.assertEqual(self.hightest_card.value, 6)
23+
24+
def test_cards_total(self):
25+
self.assertEqual(self.card_game.cards_total(self.deck_of_cards),"You have a total of 12")

part_2_code/src/__init__.py

Whitespace-only changes.

part_2_code/src/card.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
class Card:
3+
4+
def __init__(self, suit, value):
5+
self.suit = suit
6+
self.value = value

part_2_code/src/card_game.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Testing task 2 code:
2+
3+
# Carry out dynamic testing on the code below.
4+
5+
# Correct the errors below that you spotted in task 1.
6+
7+
class CardGame:
8+
9+
10+
def check_for_ace(self, card):
11+
if card.value == 1:
12+
return True
13+
else:
14+
return False
15+
16+
17+
def highest_card(self, card1, card2):
18+
if card1.value > card2.value:
19+
return card1
20+
else:
21+
return card2
22+
23+
24+
25+
def cards_total(self, cards):
26+
total = 0
27+
for card in cards:
28+
total += card.value
29+
return "You have a total of " + str(total)

0 commit comments

Comments
 (0)