-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 0 0 0 0 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 1 2 2 2 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-1 0 0 1 0 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 1 2 1 2 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# CS0 Lab - OOP and Unittesting | ||
|
||
Possible Points: 100 | ||
|
||
Write a Python program to solve the Kattis problem - Bijele - [https://open.kattis.com/problems/bijele](https://open.kattis.com/problems/bijele) . Read the problem statement carefully to design a correct solution using OOP and unittest. | ||
|
||
## Lab Instructions | ||
|
||
1. Open your CS0Lab-... repo in VS Code | ||
2. Create lab folder **oop** inside your CS0Lab-... repository | ||
3. Inside the lab folder, create two files. | ||
4. Type the partial code stub provided and fix all FIXMEs. (80 points) | ||
5. Follow best programming practices by using proper white spaces, comments, etc. | ||
|
||
```note | ||
IMPORTANT: Never ask the user telling what data to enter for Kattis problems. Kattis knows what to enter. | ||
Directly read the input. Print only the answer as displayed in the sample output. | ||
Print as asked: nothing less; nothing more! | ||
Kattis is a computer program that provides specific input and expects exact output – to a space to give the correct verdict. | ||
``` | ||
|
||
6. Run unit test using pytest and create screenshot when all the test cases pass. Install pytest if required. Pick one of the following ways to run pytest. | ||
|
||
```bash | ||
$ pytest --version | ||
$ pip install -U pytest | ||
$ pytest . | ||
$ python -m pytest . | ||
``` | ||
|
||
7. Test the whole program manually. While testing, provide input using the same format as described in the Input section and shown in input samples. | ||
8. Upload only the solution script to Kattis. You can test your solution as many times as you wish. Kattis uses its own hidden test cases to test your program against. However, your goal is to get the accepted verdict in the first try. | ||
9. Create screenshots showing your local testing and the kattis final Accept verdict and save them to the lab folder. (10 points) | ||
10. Update your README file (10 points) as shown here: [https://github.com/rambasnet/csci000-astudent](https://github.com/rambasnet/csci000-astudent) | ||
|
||
## Submission | ||
|
||
- Make sure to format the code using pep8 or black before submission. | ||
- Add all the relevant source file(s), documents, and screenshots into the correct lab folder and do a final add, commit, and push before the due date. | ||
|
||
```bash | ||
$ git pull | ||
$ git status | ||
$ git add <filename>… - add each file in the red that is part of this lab | ||
$ git status | ||
$ git commit -m "Final Submission" | ||
$ git push | ||
$ git status | ||
``` | ||
|
||
- Check and make sure the files are actually pushed to your GitHub repo on github.com. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
Date: FIXME | ||
Using OOP concept, solve: Bijele - https://open.kattis.com/problems/bijele | ||
Algorithm: | ||
1. Create chess.py module to define the the Chess class | ||
2. Define the __init__ method to initialize the Chess class | ||
3. Define the __str__ method to return the string representation of the Chess class | ||
4. Define the __sub__ method to return the difference between two Chess objects | ||
5. print the difference as shown in the sample output | ||
""" | ||
|
||
from chess import Chess | ||
|
||
|
||
def main() -> None: | ||
# the actual chess pieces count | ||
actual_chess = Chess(1, 1, 2, 2, 2, 8) | ||
# FIXME - read the chess pieces count from the input | ||
pieces = 0, 0, 0, 0, 0, 0 # FIXME | ||
given_chess = Chess(*pieces) | ||
# FIXME - create a Chess object using the input data | ||
# FIXME - print the difference between the actual and input chess pieces count | ||
ans = actual_chess - given_chess # creates a new Chess object | ||
print(ans) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Module to define the Chess class. | ||
""" | ||
|
||
|
||
class Chess: | ||
def __init__(self, king=1, queen=1, rooks=2, bishops=2, knights=2, pawns=8): | ||
self.king = king | ||
self.queen = queen | ||
# update the rest of the attributes using the arguments | ||
self.rooks = 0 # FIXME | ||
self.bishops = 0 # FIXME | ||
self.knights = 0 # FIXME | ||
self.pawns = 0 # FIXME | ||
|
||
def __str__(self): | ||
return f'{self.king} {self.queen} {self.rooks} {self.bishops} {self.knights} {self.pawns}' | ||
|
||
def __sub__(self, other: 'Chess'): | ||
k_diff = self.king - other.king | ||
q_diff = self.queen - other.queen | ||
r_diff = self.rooks - other.rooks | ||
# FIXME - update the rest of the attributes' differences | ||
b_diff = 0 # FIXME | ||
kn_diff = 0 # FIXME | ||
p_diff = 0 # FIXME | ||
return Chess(k_diff, q_diff, r_diff, b_diff, kn_diff, p_diff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Module to test the Chess class. | ||
""" | ||
|
||
from chess import Chess | ||
|
||
|
||
def test__init__() -> None: | ||
"""Test the __init__ method""" | ||
chess = Chess(1, 1, 2, 2, 2, 8) | ||
assert chess.king == 1 | ||
assert chess.queen == 1 | ||
assert chess.rooks == 2 | ||
assert chess.bishops == 2 | ||
assert chess.knights == 2 | ||
assert chess.pawns == 8 | ||
|
||
# add two test function to __init__ method to test the attributes are correctly initialized | ||
|
||
|
||
def test__str__() -> None: | ||
"""Test the __str__ metho""" | ||
chess = Chess() | ||
assert str(chess) == '1 1 2 2 2 8' | ||
|
||
|
||
# add two test function to __str__ method to test the string representation is correct | ||
|
||
def test__diff__(): | ||
"""Test the __sub__ method""" | ||
chess1 = Chess(1, 1, 2, 2, 2, 8) | ||
chess2 = Chess(0, 1, 1, 2, 1, 8) | ||
chess3 = chess1 - chess2 | ||
assert chess3.king == 1 | ||
assert chess3.queen == 0 | ||
assert chess3.rooks == 1 | ||
assert chess3.bishops == 0 | ||
assert chess3.knights == 1 | ||
assert chess3.pawns == 0 | ||
|
||
|
||
# add two test function to __sub__ method to test the difference is correct |