Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
project05
Commits
94042ddf
Commit
94042ddf
authored
7 months ago
by
Antonio M. Caceres
Browse files
Options
Download
Email Patches
Plain Diff
Add small pivot matrix tests to test_pivot_matrix.py.
parent
c80c392a
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests.json
+1
-1
tests.json
tests/3.gaussian_elimination/test_pivot_matrix.py
+40
-2
tests/3.gaussian_elimination/test_pivot_matrix.py
with
41 additions
and
3 deletions
+41
-3
tests.json
View file @
94042ddf
{
"0.elements"
:
{
"test_get_all_atoms.py"
:
[
"test_get_all_atoms"
],
"test_grams_to_mols.py"
:
[
"test_grams_to_mols"
],
"test_molar_mass.py"
:
[
"test_molar_mass"
]},
"1.balancing"
:
{
"test_balance.py"
:
[
"test_check_balance_equation"
],
"test_make_atom_vector.py"
:
[
"test_make_atom_vector"
],
"test_make_compound_matrix.py"
:
[
"test_make_compound_matrix"
],
"test_make_dictionary_solution.py"
:
[
"test_make_dictionary_solution"
],
"test_make_dummy_equation.py"
:
[
"test_make_dummy_equation"
],
"test_make_system_of_equations.py"
:
[
"test_make_system_of_equations"
],
"test_scale_solution.py"
:
[
"test_scale_solution"
]},
"2.matrix_operations"
:
{
"test_negate_matrix.py"
:
[
"test_negate_matrix"
],
"test_transpose_matrix.py"
:
[
"test_transpose_matrix"
]},
"3.gaussian_elimination"
:
{
"test_back_substitute.py"
:
[
"test_back_substitute"
],
"test_gaussian_elimination.py"
:
[
"test_gaussian_elimination"
],
"test_pivot_matrix.py"
:
[
"test_pivot_matrix"
],
"test_ref.py"
:
[
"test_ref_zero_row"
,
"test_ref_large_matrix"
],
"test_scale_matrix.py"
:
[
"test_scale_matrix"
]},
"4.limiting_reactant"
:
{
"test_limiting_reactant.py"
:
[
"test_limiting_reactant"
],
"test_ratio.py"
:
[
"test_ratio"
]},
"5.theoretical_yield"
:
{
"test_theoretical_yield.py"
:
[
"test_theoretical_yield"
]}}
{
"0.elements"
:
{
"test_get_all_atoms.py"
:
[
"test_get_all_atoms"
],
"test_grams_to_mols.py"
:
[
"test_grams_to_mols"
],
"test_molar_mass.py"
:
[
"test_molar_mass"
]},
"1.balancing"
:
{
"test_balance.py"
:
[
"test_check_balance_equation"
],
"test_make_atom_vector.py"
:
[
"test_make_atom_vector"
],
"test_make_compound_matrix.py"
:
[
"test_make_compound_matrix"
],
"test_make_dictionary_solution.py"
:
[
"test_make_dictionary_solution"
],
"test_make_dummy_equation.py"
:
[
"test_make_dummy_equation"
],
"test_make_system_of_equations.py"
:
[
"test_make_system_of_equations"
],
"test_scale_solution.py"
:
[
"test_scale_solution"
]},
"2.matrix_operations"
:
{
"test_negate_matrix.py"
:
[
"test_negate_matrix"
],
"test_transpose_matrix.py"
:
[
"test_transpose_matrix"
]},
"3.gaussian_elimination"
:
{
"test_back_substitute.py"
:
[
"test_back_substitute"
],
"test_gaussian_elimination.py"
:
[
"test_gaussian_elimination"
],
"test_pivot_matrix.py"
:
[
"test_pivot_matrix
_small"
,
"test_pivot_matrix_large
"
],
"test_ref.py"
:
[
"test_ref_zero_row"
,
"test_ref_large_matrix"
],
"test_scale_matrix.py"
:
[
"test_scale_matrix"
]},
"4.limiting_reactant"
:
{
"test_limiting_reactant.py"
:
[
"test_limiting_reactant"
],
"test_ratio.py"
:
[
"test_ratio"
]},
"5.theoretical_yield"
:
{
"test_theoretical_yield.py"
:
[
"test_theoretical_yield"
]}}
This diff is collapsed.
Click to expand it.
tests/3.gaussian_elimination/test_pivot_matrix.py
View file @
94042ddf
import
random
import
pytest
from
fractions
import
Fraction
from
support.matrix
import
MutableRationalMatrix2D
from
tests.helpers.naming
import
apply_names
from
tests.helpers.matrix_helpers
import
generate_random_pivot_matrices
...
...
@@ -10,8 +10,46 @@ ref_pivot_matrix = driver_import_reference('matrix_operations.pivot_matrix')
from
src.matrix_operations
import
pivot_matrix
_SMALL_PIVOTS
=
[
[[
1
,
2
,
3
,
4
],
[
9
,
8
,
7
,
6
],
[
7
,
3
,
4
,
8
],
],
[[
1
,
2
,
3
,
4
,
5
],
[
3
,
2
,
8
,
6
,
1
],
[
5
,
7
,
3
,
2
,
1
],
[
8
,
2
,
6
,
4
,
3
],
],
[[
1
,
2
,
3
,
4
,
5
,
6
],
[
8
,
2
,
8
,
3
,
6
,
2
],
[
9
,
4
,
3
,
7
,
6
,
3
],
[
0
,
0
,
0
,
0
,
0
,
0
],
[
1
,
2
,
3
,
4
,
5
,
6
],
]
]
def
_generate_small_pivot_matrices
():
matrices
=
[]
for
arr
in
_SMALL_PIVOTS
:
mat
=
MutableRationalMatrix2D
((
len
(
arr
),
len
(
arr
[
0
])))
for
i
in
range
(
mat
.
dimensions
[
0
]):
for
j
in
range
(
mat
.
dimensions
[
1
]):
mat
[
i
][
j
]
=
Fraction
(
arr
[
i
][
j
])
matrices
.
append
([
mat
])
return
matrices
@
pytest
.
mark
.
parametrize
(
'matrix'
,
apply_names
(
'pivot_matrix'
,
[
False
],
_generate_small_pivot_matrices
()))
def
test_pivot_matrix_small
(
matrix
:
MutableRationalMatrix2D
):
for
col
in
range
(
2
,
len
(
matrix
)):
correct
=
ref_pivot_matrix
(
matrix
.
mutable
(),
col
)
out
=
pivot_matrix
(
matrix
,
col
)
assert
correct
==
out
@
pytest
.
mark
.
parametrize
(
'matrix'
,
apply_names
(
'pivot_matrix'
,
[
False
],
generate_random_pivot_matrices
()))
def
test_pivot_matrix
(
matrix
:
MutableRationalMatrix2D
):
def
test_pivot_matrix
_large
(
matrix
:
MutableRationalMatrix2D
):
for
col
in
range
(
2
,
len
(
matrix
)):
correct
=
ref_pivot_matrix
(
matrix
.
mutable
(),
col
)
out
=
pivot_matrix
(
matrix
,
col
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help