Skip to content

Instantly share code, notes, and snippets.

@M1nified
Created January 15, 2020 16:40
Show Gist options
  • Save M1nified/d81dda4ae100aa3d7c7f7480cb7933d1 to your computer and use it in GitHub Desktop.
Save M1nified/d81dda4ae100aa3d7c7f7480cb7933d1 to your computer and use it in GitHub Desktop.
UJ-Obiektowe-TestyMutacyjne

Mutation testing

Run

docker-compose up
version: "2"
services:
test:
build: .
volumes:
- .:/src
working_dir: /src
command: mut.py --target matMul.py --unit-test matMul_test.py -m
FROM python:3.7-slim
RUN pip3 install numpy
RUN pip3 install mutpy
version: "2"
services:
test:
build: .
volumes:
- .:/src
working_dir: /src
command: mut.py --target matMul.py --unit-test matMul_test.py -m
FROM python:3.7-slim
RUN pip3 install numpy
RUN pip3 install mutpy
class MatrixDimmensionsMismatch(Exception):
pass
def matMul(mat1, mat2):
countRows1 = len(mat1)
countRows2 = len(mat2)
countCols1 = len(mat1[0])
countCols2 = len(mat2[0])
if countCols1 != countRows2:
raise MatrixDimmensionsMismatch
result = [[0 for _ in range(0, min(countCols1, countCols2))] for _ in range(0,min(countRows1, countRows2))]
for row1 in range(0,countRows1):
for col1 in range(0, countCols1):
for col2 in range(0, countCols2) :
result[row1][col2] += mat1[row1][col1] * mat2[col1][col2]
return result
mat1 = [
[2,1,3],
[-1,4,0]
]
mat2 = [
[1,3,2],
[-2,0,1],
[5,-3,2]
]
# matMul(mat1, mat2)
# matMul(
# [[1]],
# [[1]]
# )
import numpy as np
import unittest
from matMul import matMul, MatrixDimmensionsMismatch
mat1 = [
[2,1,3],
[-1,4,0]
]
mat2 = [
[1,3,2],
[-2,0,1],
[5,-3,2]
]
npMat1 = np.array(mat1)
npMat2 = np.array(mat2)
corrMat1x2 = (npMat1 @ npMat2).tolist()
class TestStringMethods(unittest.TestCase):
def test_correct_mul(self):
self.assertListEqual(matMul(mat1, mat2), corrMat1x2)
def test_dimension_mismatch(self):
with self.assertRaises(MatrixDimmensionsMismatch):
matMul(
[[1,2]],
[[1]]
)
if __name__ == '__main__':
unittest.main()
# Mutation testing
## Run
```bash
docker-compose up
```
class MatrixDimmensionsMismatch(Exception):
pass
def matMul(mat1, mat2):
countRows1 = len(mat1)
countRows2 = len(mat2)
countCols1 = len(mat1[0])
countCols2 = len(mat2[0])
if countCols1 != countRows2:
raise MatrixDimmensionsMismatch
result = [[0 for _ in range(0, min(countCols1, countCols2))] for _ in range(0,min(countRows1, countRows2))]
for row1 in range(0,countRows1):
for col1 in range(0, countCols1):
for col2 in range(0, countCols2) :
result[row1][col2] += mat1[row1][col1] * mat2[col1][col2]
return result
mat1 = [
[2,1,3],
[-1,4,0]
]
mat2 = [
[1,3,2],
[-2,0,1],
[5,-3,2]
]
# matMul(mat1, mat2)
# matMul(
# [[1]],
# [[1]]
# )
import numpy as np
import unittest
from matMul import matMul, MatrixDimmensionsMismatch
mat1 = [
[2,1,3],
[-1,4,0]
]
mat2 = [
[1,3,2],
[-2,0,1],
[5,-3,2]
]
npMat1 = np.array(mat1)
npMat2 = np.array(mat2)
corrMat1x2 = (npMat1 @ npMat2).tolist()
class TestStringMethods(unittest.TestCase):
def test_correct_mul(self):
self.assertListEqual(matMul(mat1, mat2), corrMat1x2)
def test_dimension_mismatch(self):
with self.assertRaises(MatrixDimmensionsMismatch):
matMul(
[[1,2]],
[[1]]
)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment