Skip to content

Instantly share code, notes, and snippets.

View sanjitk7's full-sized avatar
🛠️
Building. Learning.

Sanjit Kumar sanjitk7

🛠️
Building. Learning.
View GitHub Profile
@sanjitk7
sanjitk7 / bundleTests.py
Created June 16, 2020 08:38
using test suite
testSuite1 = unittest.TestSuite()
testSuite1.addTest(unittest.makeSuite(myTest1))
runner=unittest.TextTestRunner()
runner.run(testSuite1)
@sanjitk7
sanjitk7 / testFind.py
Last active June 16, 2020 08:37
creating a test suite
import unittest
loader = unittest.TestLoader()
tests = loader.discover('.','test*')
testRunner = unittest.runner.TextTestRunner()
testRunner.run(tests)
@sanjitk7
sanjitk7 / matrixOperations.py
Created June 16, 2020 07:56
write the multiply function after its test is written
def multiply (A,B):
C = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(A)):
for j in range(len(A[0])):
for k in range(len(B)):
C[i][j] += A[i][k] * B[k][j]
return C
@sanjitk7
sanjitk7 / testMatrix.py
Created June 16, 2020 07:49
added multiplication test before multiplication function is written
def test_multiply(self):
A = [[1,1,1],[1,1,1],[1,1,1]]
B = [[1,1,1],[1,1,1],[1,1,1]]
product = [[3,3,3],[3,3,3],[3,3,3]]
self.assertEqual(multiply(A,B),product)
@sanjitk7
sanjitk7 / testMatrix.py
Created June 16, 2020 07:24
write test before the add function is written
import unittest
from matrixOperations import add
class TestMatrix(unittest.TestCase):
def test_add(self):
A = [[1,1,1],[1,1,1],[1,1,1]]
B = [[1,1,1],[1,1,1],[1,1,1]]
sum = [[2,2,2],[2,2,2],[2,2,2]]
self.assertEqual(add(A,B),sum)
def add(A,B):
C = [[0,0,0],[0,0,0],[0,0,0]]
for i in range(0,len(A)):
for j in range(0,len(A[0])):
C[i][j] = A[i][j] + B[i][j]
return C
# in isCamelCase the regex now only matches keywords only
# with constituent words starting in A-H
x = re.search(r"(.+?)([A-H])",word)
@sanjitk7
sanjitk7 / testAbbr.py
Created May 17, 2020 06:16
test method for camelCaseSplit
def test_camelCaseSplit(self):
self.assertEqual(camelCaseSplit("theDarkKnightRises"),["the","Dark","Knight","Rises"])
self.assertEqual(camelCaseSplit("helloW"),["hello","W"])
self.assertEqual(camelCaseSplit("helloIWorld"),["hello","I","World"])
with self.assertRaises(TypeError):
camelCaseSplit(1234)
@sanjitk7
sanjitk7 / abbreviation_generator.py
Last active May 17, 2020 07:00
Function to Split Camel Case Keyword
def camelCaseSplit(word):
if (isCamelCase(word)):
return re.split(r"(?=[A-Z])", word)
else:
return []
@sanjitk7
sanjitk7 / testAbbr.py
Last active May 17, 2020 06:24
Test Program for abbreviation_generator.py
import unittest
from abbreviation_generator import isCamelCase,camelCaseSplit
class TestKeywords(unittest.TestCase):
def test_isCamelCase(self):
self.assertTrue(isCamelCase("janeDoe"))
self.assertTrue(isCamelCase("imCamelCase"))
self.assertTrue(isCamelCase("has$InWord"))
self.assertFalse(isCamelCase("ImPascalCase"))
self.assertFalse(isCamelCase("has_underscore"))