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
project04
Commits
3f0b770c
Commit
3f0b770c
authored
8 months ago
by
Antonio Caceres
Browse files
Options
Download
Email Patches
Plain Diff
Specify imports and fix formatting in tests/ directory.
parent
aafca03a
master
No related merge requests found
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
tests/0.D/test_task1.py
+4
-9
tests/0.D/test_task1.py
tests/1.C/test_task2.py
+0
-5
tests/1.C/test_task2.py
tests/1.C/test_task3.py
+29
-32
tests/1.C/test_task3.py
tests/2.B/test_task4.py
+0
-6
tests/2.B/test_task4.py
tests/2.B/test_task5.py
+18
-21
tests/2.B/test_task5.py
tests/3.A/test_task6.py
+29
-32
tests/3.A/test_task6.py
tests/helpers/constants_for_testing.py
+2
-5
tests/helpers/constants_for_testing.py
tests/helpers/fake_objects.py
+1
-3
tests/helpers/fake_objects.py
with
83 additions
and
113 deletions
+83
-113
tests/0.D/test_task1.py
View file @
3f0b770c
import
subprocess
import
sys
try
:
from
vpython
import
*
from
vpython
import
box
,
cylinder
,
pi
,
sphere
except
ImportError
:
subprocess
.
check_call
([
sys
.
executable
,
"-m"
,
"pip"
,
"install"
,
'vpython'
])
finally
:
from
vpython
import
*
from
vpython
import
box
,
cylinder
,
pi
,
sphere
import
pytest
import
os
import
sys
# type: ignore
from
src.constants
import
R
,
RANGE
,
SPREADSHEET_ID
,
THETA_INIT
from
src.sheets_api
import
get_values
,
update_values
,
get_pendulum_info
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
from
src.constants
import
*
from
tests.helpers.constants_for_testing
import
VPYTHON_COLOR_MAP
import
src.special_cradles
as
main
...
...
This diff is collapsed.
Click to expand it.
tests/1.C/test_task2.py
View file @
3f0b770c
from
vpython
import
*
import
pytest
,
os
,
sys
# type: ignore
from
src.constants
import
*
from
src.sheets_api
import
*
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
import
src.swinging
as
main
...
...
This diff is collapsed.
Click to expand it.
tests/1.C/test_task3.py
View file @
3f0b770c
from
vpython
import
*
from
vpython
import
vector
,
color
,
textures
import
pytest
,
os
,
sys
# type: ignore
from
src.constants
import
*
from
src.sheets_api
import
*
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
from
tests.helpers.fake_objects
import
FakePend
import
src.swinging
as
main
@
pytest
.
mark
.
parametrize
(
"theta1, omega1, theta2, omega2, r_param, dt, g,
\
...
...
@@ -12,39 +9,39 @@ import src.swinging as main
expected_theta2, expected_bob_pos1, expected_bob_pos2,
\
expected_axis_pos1, expected_axis_pos2"
,
[
# base case
(
0
,
0
,
0
,
0
,
100
,
0.01
,
0
,
0.0
,
0.0
,
0.0
,
0.0
,
(
0.0
,
-
99.0
,
0.0
),
\
(
0
,
0
,
0
,
0
,
100
,
0.01
,
0
,
0.0
,
0.0
,
0.0
,
0.0
,
(
0.0
,
-
99.0
,
0.0
),
(
0.0
,
-
98.0
,
0.0
),
(
0.0
,
-
100.0
,
0.0
),
(
0.0
,
-
100.0
,
0.0
)),
(
0.5
,
1
,
0.1
,
0
,
1
,
1
,
1
,
0.520574461395797
,
1.020574461395797
,
\
-
0.09983341664682815
,
0.0001665833531718508
,
(
0.852409
,
0.477124
,
0.0
),
\
(
0.5
,
1
,
0.1
,
0
,
1
,
1
,
1
,
0.520574461395797
,
1.020574461395797
,
-
0.09983341664682815
,
0.0001665833531718508
,
(
0.852409
,
0.477124
,
0.0
),
(
0.000166583
,
1.0
,
0.0
),
(
0.852409
,
-
0.522876
,
0.0
),
(
0.000166583
,
-
1.0
,
0.0
)),
(
0.1
,
0.2
,
0.3
,
0.4
,
1
,
0.01
,
9.81
,
0.19020634182694618
,
0.10190206341826946
,
\
0.3710094677265226
,
0.30371009467726523
,
\
(
0.10172579593859243
,
0.005187523982203013
,
0.0
),
\
(
0.2990625534670365
,
1.0457664913063596
,
0.0
),
\
(
0.10172579593859243
,
-
0.994812476017797
,
0.0
),
\
(
0.2990625534670365
,
-
0.9542335086936404
,
0.0
)),
(
6.28
,
1
,
-
6.28
,
1
,
1.5
,
1
,
10
,
1.0212353452875866
,
7.301235345287587
,
\
0.9787646547124134
,
-
5.301235345287587
,
\
(
1.2766287883935794
,
0.21246019996146148
,
0.0
),
\
(
1.2473729454328544
,
1.1668969241431375
,
0.0
),
\
(
1.2766287883935794
,
-
0.7875398000385385
,
0.0
),
\
(
1.2473729454328544
,
-
0.8331030758568625
,
0.0
)),
(
1.1
,
0
,
1.2
,
0
,
5
,
0.001
,
2
,
-
0.00035648294402457415
,
1.099999643517056
,
\
-
0.00037281563438689054
,
1.1999996271843656
,
\
(
4.45603599181049
,
-
1.2679821956288597
,
0.0
),
\
(
4.660194754372627
,
0.18820949022304223
,
0.0
),
\
(
4.45603599181049
,
-
2.2679821956288597
,
0.0
),
\
(
4.660194754372627
,
-
1.8117905097769578
,
0.0
))
(
0.1
,
0.2
,
0.3
,
0.4
,
1
,
0.01
,
9.81
,
0.19020634182694618
,
0.10190206341826946
,
0.3710094677265226
,
0.30371009467726523
,
(
0.10172579593859243
,
0.005187523982203013
,
0.0
),
(
0.2990625534670365
,
1.0457664913063596
,
0.0
),
(
0.10172579593859243
,
-
0.994812476017797
,
0.0
),
(
0.2990625534670365
,
-
0.9542335086936404
,
0.0
)),
(
6.28
,
1
,
-
6.28
,
1
,
1.5
,
1
,
10
,
1.0212353452875866
,
7.301235345287587
,
0.9787646547124134
,
-
5.301235345287587
,
(
1.2766287883935794
,
0.21246019996146148
,
0.0
),
(
1.2473729454328544
,
1.1668969241431375
,
0.0
),
(
1.2766287883935794
,
-
0.7875398000385385
,
0.0
),
(
1.2473729454328544
,
-
0.8331030758568625
,
0.0
)),
(
1.1
,
0
,
1.2
,
0
,
5
,
0.001
,
2
,
-
0.00035648294402457415
,
1.099999643517056
,
-
0.00037281563438689054
,
1.1999996271843656
,
(
4.45603599181049
,
-
1.2679821956288597
,
0.0
),
(
4.660194754372627
,
0.18820949022304223
,
0.0
),
(
4.45603599181049
,
-
2.2679821956288597
,
0.0
),
(
4.660194754372627
,
-
1.8117905097769578
,
0.0
))
])
def
test_full_swing_update
(
theta1
,
omega1
,
theta2
,
omega2
,
r_param
,
dt
,
g
,
\
expected_omega1
,
expected_theta1
,
expected_omega2
,
\
expected_theta2
,
expected_bob_pos1
,
expected_bob_pos2
,
\
expected_axis_pos1
,
expected_axis_pos2
):
def
test_full_swing_update
(
theta1
,
omega1
,
theta2
,
omega2
,
r_param
,
dt
,
g
,
expected_omega1
,
expected_theta1
,
expected_omega2
,
expected_theta2
,
expected_bob_pos1
,
expected_bob_pos2
,
expected_axis_pos1
,
expected_axis_pos2
):
pend1
=
{
"pendulum"
:
FakePend
(
vector
(
0
,
1
,
0
),
1
,
theta1
,
color
.
white
,
textures
.
metal
).
pendulum
,
"theta"
:
theta1
,
"omega"
:
omega1
}
...
...
This diff is collapsed.
Click to expand it.
tests/2.B/test_task4.py
View file @
3f0b770c
from
vpython
import
*
import
pytest
,
os
,
sys
# type: ignore
from
src.constants
import
*
from
src.sheets_api
import
*
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
import
visualize_cradle_run
as
main
@
pytest
.
mark
.
parametrize
(
"e, omega, omega2, m1, m2, r_param, expected_omega, expected_omega2"
,
[
...
...
This diff is collapsed.
Click to expand it.
tests/2.B/test_task5.py
View file @
3f0b770c
from
vpython
import
*
import
pytest
,
os
,
sys
# type: ignore
from
src.constants
import
*
from
src.sheets_api
import
*
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
from
vpython
import
vector
,
color
,
textures
import
visualize_cradle_run
as
main
from
tests.helpers.fake_objects
import
FakeBob
@
pytest
.
mark
.
parametrize
(
"pos1, omega1, m1, rad1, e1,
\
pos2, omega2, m2, rad2, e2,
\
expected_omega1, expected_omega2,
\
reverse_expected_omega1, reverse_expected_omega2"
,
[
(
vector
(
1
,
0
,
0
),
1
,
1
,
0.5
,
1
,
\
vector
(
0
,
0
,
0
),
0.5
,
2
,
0.5
,
0
,
\
0.3333333333333333
,
0.8333333333333334
,
\
0.6666666666666666
,
0.6666666666666666
),
(
vector
(
1.05
,
0
,
0
),
1
,
1
,
0.5
,
1
,
\
vector
(
0
,
0
,
0
),
0.5
,
2
,
0.5
,
0
,
\
0.3333333333333333
,
0.8333333333333334
,
\
0.6666666666666666
,
0.6666666666666666
),
(
vector
(
2
,
1
,
0.3
),
0.1
,
10
,
1.5
,
0.7
,
\
vector
(
0.5
,
1.3
,
0.7
),
0.3
,
2.7
,
0.5
,
\
0.4
,
0.17228346456692917
,
0.03228346456692915
,
\
0.15952755905511815
,
0.07952755905511813
),
(
vector
(
1
,
0
,
0
),
1
,
1
,
0.5
,
1
,
vector
(
0
,
0
,
0
),
0.5
,
2
,
0.5
,
0
,
0.3333333333333333
,
0.8333333333333334
,
0.6666666666666666
,
0.6666666666666666
),
(
vector
(
1.05
,
0
,
0
),
1
,
1
,
0.5
,
1
,
vector
(
0
,
0
,
0
),
0.5
,
2
,
0.5
,
0
,
0.3333333333333333
,
0.8333333333333334
,
0.6666666666666666
,
0.6666666666666666
),
(
vector
(
2
,
1
,
0.3
),
0.1
,
10
,
1.5
,
0.7
,
vector
(
0.5
,
1.3
,
0.7
),
0.3
,
2.7
,
0.5
,
0.4
,
0.17228346456692917
,
0.03228346456692915
,
0.15952755905511815
,
0.07952755905511813
),
# very close to condition - make sure your inequality is <= radius_sum * 1.05
(
vector
(
1.04
,
0
,
0
),
1.4
,
10
,
0.25
,
0.9
,
\
vector
(
0
,
0
,
0
),
2.3
,
2.7
,
0.75
,
0.1
,
\
1.7635433070866144
,
0.9535433070866143
,
\
1.6104724409448818
,
1.5204724409448822
)
(
vector
(
1.04
,
0
,
0
),
1.4
,
10
,
0.25
,
0.9
,
vector
(
0
,
0
,
0
),
2.3
,
2.7
,
0.75
,
0.1
,
1.7635433070866144
,
0.9535433070866143
,
1.6104724409448818
,
1.5204724409448822
)
])
def
test_handle_two_bobs_collision
(
pos1
,
omega1
,
m1
,
rad1
,
e1
,
\
pos2
,
omega2
,
m2
,
rad2
,
e2
,
\
...
...
This diff is collapsed.
Click to expand it.
tests/3.A/test_task6.py
View file @
3f0b770c
from
vpython
import
*
import
pytest
,
os
,
sys
# type: ignore
from
src.constants
import
*
from
src.sheets_api
import
*
from
tests.helpers.fake_objects
import
*
from
tests.helpers.constants_for_testing
import
*
from
vpython
import
vector
,
color
,
textures
import
visualize_cradle_run
as
main
from
tests.helpers.fake_objects
import
FakePend
@
pytest
.
mark
.
parametrize
(
"pos1, theta1, omega1, m1, e1,
\
pos2, theta2, omega2, m2, e2,
\
...
...
@@ -14,35 +11,35 @@ import visualize_cradle_run as main
exp_omega1, exp_theta1,
\
exp_omega2, exp_theta2,
\
exp_omega3, exp_theta3"
,[
((
vector
(
1
,
0
,
0
),
1
,
0.5
,
2
,
1
,
\
vector
(
0
,
0
,
0
),
2
,
0.5
,
3
,
0
,
\
vector
(
1.05
,
0
,
0
),
1
,
0.5
,
2.5
,
1
,
\
1
,
0.01
,
9.81
,
\
0.41745169639034535
,
1.0041745169639034
,
\
0.41079792242840063
,
2.004107979224284
,
\
0.41745169639034535
,
1.0041745169639034
)),
(
vector
(
1
,
0
,
0
),
1
,
1.5
,
2
,
1
,
\
vector
(
1.1
,
0
,
0
),
2
,
1.5
,
3
,
1
,
\
vector
(
1.05
,
0
,
0
),
1
,
1.5
,
4.5
,
1
,
\
0.5
,
0.01
,
10
,
\
1.3317058030384206
,
1.0133170580303843
,
\
1.3181405146348637
,
2.013181405146349
,
\
1.3317058030384206
,
1.0133170580303843
),
(
vector
(
0.5
,
0.3
,
2.2
),
0.5
,
0.1
,
2
,
0
,
\
vector
(
0.7
,
0.2
,
2.5
),
2.2
,
0
,
2
,
0
,
\
vector
(
1
,
0.1
,
3.3
),
3.1
,
1
,
2
,
0
,
\
1.5
,
0.001
,
5
,
\
0.09840191487131933
,
0.5000984019148713
,
\
-
0.002694988012731967
,
2.1999973050119874
,
\
0.999861397791889
,
3.100999861397792
)
((
vector
(
1
,
0
,
0
),
1
,
0.5
,
2
,
1
,
vector
(
0
,
0
,
0
),
2
,
0.5
,
3
,
0
,
vector
(
1.05
,
0
,
0
),
1
,
0.5
,
2.5
,
1
,
1
,
0.01
,
9.81
,
0.41745169639034535
,
1.0041745169639034
,
0.41079792242840063
,
2.004107979224284
,
0.41745169639034535
,
1.0041745169639034
)),
(
vector
(
1
,
0
,
0
),
1
,
1.5
,
2
,
1
,
vector
(
1.1
,
0
,
0
),
2
,
1.5
,
3
,
1
,
vector
(
1.05
,
0
,
0
),
1
,
1.5
,
4.5
,
1
,
0.5
,
0.01
,
10
,
1.3317058030384206
,
1.0133170580303843
,
1.3181405146348637
,
2.013181405146349
,
1.3317058030384206
,
1.0133170580303843
),
(
vector
(
0.5
,
0.3
,
2.2
),
0.5
,
0.1
,
2
,
0
,
vector
(
0.7
,
0.2
,
2.5
),
2.2
,
0
,
2
,
0
,
vector
(
1
,
0.1
,
3.3
),
3.1
,
1
,
2
,
0
,
1.5
,
0.001
,
5
,
0.09840191487131933
,
0.5000984019148713
,
-
0.002694988012731967
,
2.1999973050119874
,
0.999861397791889
,
3.100999861397792
)
])
def
test_newton_cradle_tick
(
pos1
,
theta1
,
omega1
,
m1
,
e1
,
\
pos2
,
theta2
,
omega2
,
m2
,
e2
,
\
pos3
,
theta3
,
omega3
,
m3
,
e3
,
\
r_param
,
dt
,
g
,
\
exp_omega1
,
exp_theta1
,
\
exp_omega2
,
exp_theta2
,
\
def
test_newton_cradle_tick
(
pos1
,
theta1
,
omega1
,
m1
,
e1
,
pos2
,
theta2
,
omega2
,
m2
,
e2
,
pos3
,
theta3
,
omega3
,
m3
,
e3
,
r_param
,
dt
,
g
,
exp_omega1
,
exp_theta1
,
exp_omega2
,
exp_theta2
,
exp_omega3
,
exp_theta3
):
pend1
=
{
"pendulum"
:
FakePend
(
pos1
,
r_param
,
theta1
,
color
.
white
,
textures
.
metal
).
pendulum
,
...
...
This diff is collapsed.
Click to expand it.
tests/helpers/constants_for_testing.py
View file @
3f0b770c
from
vpython
import
*
import
pytest
,
os
,
sys
# type: ignore
import
importlib
from
src.constants
import
*
from
src.sheets_api
import
*
from
vpython
import
vector
import
pytest
,
os
,
sys
# type: ignore
VPYTHON_COLOR_MAP
=
{
'white'
:
vector
(
1
,
1
,
1
),
...
...
This diff is collapsed.
Click to expand it.
tests/helpers/fake_objects.py
View file @
3f0b770c
from
vpython
import
*
from
vpython
import
cos
,
sin
,
vector
# To avoid having VPython visualisations when testing other functions,
# we define these fake objects with the same attributes
...
...
@@ -29,5 +29,3 @@ class FakePend:
self
.
cord
=
FakeCord
(
axle_pos
,
cord_axis
)
self
.
pendulum
=
(
self
.
axle
,
self
.
bob
,
self
.
cord
)
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