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 / testAbbr.py
Last active May 16, 2020 17:53
split camel case
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)
print("hello world!")
@sanjitk7
sanjitk7 / abbreviation_generator.py
Created May 17, 2020 06:10
Function to Check if String is in camelCase
#check if the word is in camel case
#ip: "helloWorld"
#op: True
def isCamelCase(word):
#check for whitespaces
res = bool(re.search(r"\s", word))
if (not res):
x = re.search(r"^[a-z](.+?)([A-Z])",word)
if (x):
return True
@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"))
@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
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)
# in isCamelCase the regex now only matches keywords only
# with constituent words starting in A-H
x = re.search(r"(.+?)([A-H])",word)
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
@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)
@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)