Skip to content

Commit

Permalink
reorganized code; commented code; added .gitignore (issue #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
PattonYin committed Dec 6, 2023
1 parent faecffb commit 7c06769
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 118 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Python
__pycache__/
.pytest_cache/
58 changes: 58 additions & 0 deletions Python Code/problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# import the unit_testing_sample_code module
import unit_testing_sample_code as utsc

# Test for the srting_capitalizer function
def teststring(test_num, expected, actual):
if expected == actual:
print("Test " + str(test_num) + " passed!" + str(expected) + " matches " + str(actual) + ".")
else:
print("Test " + str(test_num) + " failed. Expected:" + str(expected) + ". Got: " + str(actual) + ".")

# Test for the capitalize_list function
def teststrlist(test_num, expected_list, actual_list):
print("Test " + str(test_num) + ": ")
for i in range(0, len(expected_list)):
if expected_list[i] == actual_list[i]:
print("Part " + str(i) + " in test " + str(test_num) + " passed!" + str(expected_list[i]) + " matches " + str(actual_list[i]) + ".")
else:
print("Part " + str(i) + " in test " + str(test_num) + " failed. Expected:" + str(expected_list[i]) + ". Got: " + str(actual_list[i]) + ".")

# Test for the integer_manipulator function
def testint(test_num, expected, actual):
if expected == actual:
print("Test " + str(test_num) + " passed!" + str(expected) + " matches " + str(actual) + ".")
else:
print("Test " + str(test_num) + " failed. Expected:" + str(expected) + ". Got: " + str(actual) + ".")

# Test for the manipulate_list function
def testintlist(test_num, expected_list, actual_list):
print("Test " + str(test_num) + ": ")
for i in range(0, len(expected_list)):
if expected_list[i] == actual_list[i]:
print("Part " + str(i) + " in test " + str(test_num) + " passed!" + str(expected_list[i]) + " matches " + str(actual_list[i]) + ".")
else:
print("Part " + str(i) + " in test " + str(test_num) + " failed. Expected:" + str(expected_list[i]) + ". Got: " + str(actual_list[i]) + ".")


# Print out the tests
print("\nString Capitalizer Tests:")
# test_string is the function for testing the string capitalizer and takes
# three arguments: test number (“0”), expected output value (“TwO”), and
# the call to the string_capitalizer function with the argument “two”.
teststring("0", "TwO", utsc.string_capitalizer("two"))
teststring("1", "C", utsc.string_capitalizer("c"))
teststring("2", "FouR", utsc.string_capitalizer(4))
teststring("3", "", utsc.string_capitalizer(""))

print("\nList Capitalizer Tests:")
teststrlist("0", ["TwO","C","FouR",""], utsc.capitalize_list(["two","c",4,""]))

print("\nInteger Manipulator Tests:")
testint("0", 66, utsc.integer_manipulator(10))
testint("1", 2, utsc.integer_manipulator(2))
testint("2", 6, utsc.integer_manipulator(3))
testint("3", 0, utsc.integer_manipulator(0))
testint("4", 1, utsc.integer_manipulator("three"))

print("\nManipulate List Tests:")
testintlist("0", [66,2,6,0,1], utsc.manipulate_list([10,2,3,0,"three"]))
37 changes: 37 additions & 0 deletions Python Code/unit_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# import the unit_testing_sample_code module
import unit_testing_sample_code as utsc
import pytest

# Test for the srting_capitalizer functions
def test_string_1():
assert "TwO" == utsc.string_capitalizer("two")

def test_string_2():
assert "C" == utsc.string_capitalizer("c")

def test_string_3():
assert "FouR" == utsc.string_capitalizer('four')

def test_string_4():
assert "" == utsc.string_capitalizer("")

# Test for the capitalize_list function
def test_str_list_1():
assert ["TwO","C","FouR",""] == utsc.capitalize_list(["two","c","4",""])

# Test for the integer_manipulator function
def test_int_1():
assert 66 == utsc.integer_manipulator(10)

def test_int_2():
assert 2 == utsc.integer_manipulator(2)

def test_int_3():
assert 6 == utsc.integer_manipulator(3)

def test_int_4():
assert 0 == utsc.integer_manipulator(0)

# Test for the manipulate_list function
def test_int_list_2():
assert [66,2,6,0,0] == utsc.manipulate_list([10,2,3,0,1])
61 changes: 61 additions & 0 deletions Python Code/unit_testing_sample_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# COMP 333 Software Engineering
# Wesleyan University
# Alex Kaplan (akaplan01@wesleyan.edu) and Sebastian Zimmeck (szimmeck@wesleyan.edu)

"""
Capitalizes the first and last character of a string.
"""
def string_capitalizer(tobecapitalized):
if tobecapitalized == "":
return tobecapitalized
i = 0
try:
tbclist = [*tobecapitalized]
while i < (len(tbclist)):
if i == 0 or i == (len(tbclist) - 1):
tbclist[i] = tbclist[i].upper()
i = i + 1
tobecapitalized = ''.join(tbclist)
return tobecapitalized
except:
# If failure, return the input as is.
return tobecapitalized

"""
Capitalizes the first and last character of a string in a list of strings.
"""
def capitalize_list(slist):
i = 0
while i < len(slist):
current_string = slist[i]
slist[i] = string_capitalizer(current_string)
i = i + 1
return slist

"""
Squares, doubles, and then floor divides (by 3) an integer, in that order.
"""
def integer_manipulator(n):
try:
n = ((n*n)*2)//3
return n
except:
# If failure, return the input as is.
return n

"""
Squares, doubles, and then floor divides (by 3) an integer, in that order, in a
list of integers.
"""
def manipulate_list(intlist):
i = 0
while i < len(intlist):
intlist[i] = integer_manipulator(intlist[i])
i = i + 1
return intlist

# Sample function calls. Comment in to run.
# print(string_capitalizer("hello"))
# print(capitalize_list(["hello","good","bye"]))
# print(integer_manipulator(7))
# print(manipulate_list([7,8]))
118 changes: 0 additions & 118 deletions unit_test.py

This file was deleted.

0 comments on commit 7c06769

Please sign in to comment.