-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4288f06
commit 2acca9b
Showing
9 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Run Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
arch: [x64, arm64] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Here you can find a math library. | ||
Here you can find a math library. | ||
|
||
![Test Status](https://github.com/ep2lab/github_examples/actions/workflows/run_tests.yml/badge.svg) |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from vectormath import scalar_product, vector_product, matrix_product | ||
|
||
def test_scalar_product(): | ||
assert scalar_product([1, 2, 3], [4, 5, 6]) == 32 | ||
assert scalar_product([1, 2], [5, 6]) == 17 | ||
|
||
def test_vector_product(): | ||
assert vector_product([1, 2, 3], [4, 5, 6]) == [-3, 6, -3] | ||
assert vector_product([0, 0, 1], [1, 0, 0]) == [0, 1, 0] | ||
assert vector_product([1, 0, 0], [0, 1, 0]) == [0, 0, 1] | ||
assert vector_product([1, 1, 1], [1, 1, 1]) == [0, 0, 0] | ||
|
||
def test_matrix_product(): | ||
assert matrix_product([[1, 2], [3, 4]], [[5, 6], [7, 8]]) == [[19, 22], [43, 50]] | ||
assert matrix_product([[2, 0], [0, 2]], [[1, 2], [3, 4]]) == [[2, 4], [6, 8]] | ||
assert matrix_product([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]]) == [[58, 64], [139, 154]] | ||
assert matrix_product([[1]], [[2]]) == [[2]] | ||
assert matrix_product([[1, 2, 3]], [[4], [5], [6]]) == [[32]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .math_library import scalar_product, vector_product, matrix_product |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def scalar_product(vector1, vector2): | ||
if len(vector1) != len(vector2): | ||
raise ValueError("Vectors must be of the same length") | ||
return sum(x * y for x, y in zip(vector1, vector2)) | ||
|
||
def vector_product(vector1, vector2): | ||
if len(vector1) != 3 or len(vector2) != 3: | ||
raise ValueError("Both vectors must be of length 3") | ||
return [ | ||
vector1[1] * vector2[2] - vector1[2] * vector2[1], | ||
vector1[2] * vector2[0] - vector1[0] * vector2[2], | ||
vector1[0] * vector2[1] - vector1[1] * vector2[0] | ||
] | ||
|
||
def matrix_product(matrix1, matrix2): | ||
if len(matrix1[0]) != len(matrix2): | ||
raise ValueError("Number of columns in the first matrix must be equal to the number of rows in the second matrix") | ||
|
||
result = [[0 for _ in range(len(matrix2[0]))] for _ in range(len(matrix1))] | ||
|
||
for i in range(len(matrix1)): | ||
for j in range(len(matrix2[0])): | ||
for k in range(len(matrix2)): | ||
result[i][j] += matrix1[i][k] * matrix2[k][j] | ||
|
||
return result |