Skip to content

Commit f05f8a6

Browse files
. t test for alternative way to inject rules into fizzbuzz, and commented out db stuff in new fizzbuzz file for now (with todo comments)
Co-Authored-By: Joel Silberman <42779942+jcs-instructor@users.noreply.github.com> Co-Authored-By: 4dsherwood <4dsherwood@users.noreply.github.com>
1 parent c03050d commit f05f8a6

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed
1.61 KB
Binary file not shown.
Binary file not shown.
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The starting point for this code is from GPT4: https://chat.openai.com/share/df0f70f0-b2a0-44b7-8c48-e252ad95ca24
2-
# At this point it has no tests, etc.
3-
from pymongo import MongoClient
2+
# TODO: Uncomment out and factor out the Database logic below
3+
# from pymongo import MongoClient
44

55
class Rule:
66
def __init__(self, word, divisor):
@@ -19,22 +19,24 @@ def get_rules_from_db(collection):
1919
return rules
2020

2121
def fizz_buzz(i, rules=None):
22-
# Uses default rules from MongoDB if no rules are specified
23-
if rules is None:
24-
rules = default_rules_from_db
22+
# TODO: Use default rules from MongoDB if no rules are specified
23+
# if rules is None:
24+
# rules = default_rules_from_db
2525
output = []
2626
for rule in rules:
2727
if i % rule.divisor == 0 or str(rule.divisor) in str(i):
2828
output.append(rule.word)
2929
return ''.join(output) if output else str(i)
3030

31-
# MongoDB connection setup
32-
client = MongoClient('mongodb://localhost:27017/') # Connect to your MongoDB server
33-
db = client['fizzbuzz_db'] # Specify the database
34-
collection = db['rules'] # Specify the collection
31+
# TODO: DB work:
3532

36-
# Fetch default rules from MongoDB
37-
default_rules_from_db = get_rules_from_db(collection)
33+
# # MongoDB connection setup
34+
# client = MongoClient('mongodb://localhost:27017/') # Connect to your MongoDB server
35+
# db = client['fizzbuzz_db'] # Specify the database
36+
# collection = db['rules'] # Specify the collection
3837

39-
# Example usage of the fizz_buzz function with MongoDB
40-
print([fizz_buzz(i) for i in range(1, 16)]) # Uses default rules
38+
# # Fetch default rules from MongoDB
39+
# default_rules_from_db = get_rules_from_db(collection)
40+
41+
# # Example usage of the fizz_buzz function with MongoDB
42+
# print([fizz_buzz(i) for i in range(1, 16)]) # Uses default rules
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
from fizzbuzz import fizz_buzz, Rule
3+
4+
# Default rules
5+
default_rules = [
6+
Rule("Fizz", 3),
7+
Rule("Buzz", 5)
8+
]
9+
10+
def fizz_buzz_default(num):
11+
return fizz_buzz(num, default_rules)
12+
13+
@pytest.mark.parametrize("input, expected", [
14+
(1, "1"),
15+
(2, "2"),
16+
])
17+
def test_return_number(input, expected):
18+
assert fizz_buzz_default(input) == expected
19+
20+
@pytest.mark.parametrize("input, expected", [
21+
(3, "Fizz"),
22+
(6, "Fizz"),
23+
])
24+
def test_return_fizz(input, expected):
25+
assert fizz_buzz_default(input) == expected
26+
27+
@pytest.mark.parametrize("input, expected", [
28+
(5, "Buzz"),
29+
(10, "Buzz"),
30+
])
31+
def test_return_buzz(input, expected):
32+
assert fizz_buzz_default(input) == expected
33+
34+
@pytest.mark.parametrize("input, expected", [
35+
(15, "FizzBuzz"),
36+
(30, "FizzBuzz"),
37+
])
38+
def test_return_fizzbuzz(input, expected):
39+
assert fizz_buzz_default(input) == expected

0 commit comments

Comments
 (0)