Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/czml3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def check_values(num_points: int, values: list[Any]):
raise TypeError(
f"Input values must have either {num_points} or N * {num_points + 1} values, where N is the number of time-tagged samples."
)
if len(values) % (num_points + 1) == 0 and np.any(np.diff(values[::4]) <= 0):
if len(values) % (num_points + 1) == 0 and np.any(
np.diff(values[:: (num_points + 1)]) <= 0
):
raise TypeError("Time values must be increasing.")


Expand Down
125 changes: 125 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from czml3.types import (
Cartesian2Value,
Cartesian3Value,
Cartesian3VelocityValue,
CartographicDegreesListValue,
CartographicDegreesValue,
CartographicRadiansListValue,
Expand Down Expand Up @@ -510,3 +511,127 @@ def test_rgba_with_time():
0.5
]"""
)


def test_check_values():
assert (
str(Cartesian2Value(values=[1.0, 0.5, 0.6, 2.0, 0.7, 0.8]))
== """{
"cartesian2": [
1.0,
0.5,
0.6,
2.0,
0.7,
0.8
]
}"""
)

assert (
str(
Cartesian3Value(
values=[
1.0,
306168.0,
-5239807.0,
3611567.0,
2.0,
306168.0,
-5239807.0,
3611567.0,
]
)
)
== """[
1.0,
306168.0,
-5239807.0,
3611567.0,
2.0,
306168.0,
-5239807.0,
3611567.0
]"""
)

assert (
str(
Cartesian3VelocityValue(
values=[
1.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
2.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
]
)
)
== """[
1.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
2.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0
]"""
)

# Test for when time values are not increasing but data is sized properly
with pytest.raises(TypeError) as e:
assert (
str(
Cartesian3VelocityValue(
values=[
1.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
0.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
]
)
)
== """[
1.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0,
0.0,
306168.0,
-5239807.0,
3611567.0,
1.0,
2.0,
3.0
]"""
)
assert str(e.value) == "Time values must be increasing."