Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CAN Equation #328

Merged
merged 11 commits into from
Dec 26, 2024
Prev Previous commit
Next Next commit
update
  • Loading branch information
ManushPatell committed Dec 24, 2024
commit 1425544224ebfd0771f78ae6a0fc1ddb9ecc0df9
32 changes: 11 additions & 21 deletions scripts/cangen/tests/test_traffic.py
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -3,6 +3,9 @@


def test_no_messages():
assert (calculate_bus_load([], 500000)) == pytest.approx(0, rel=1e-5)

def test_normal_messages():
assert calculate_bus_load(
[
CANMessage(data_length=8, frequency=100),
@@ -11,16 +14,7 @@ def test_no_messages():
500000,
) == pytest.approx(3.60, rel=1e-2)

# zero frequency or negative frequency
assert calculate_bus_load(
[
CANMessage(data_length=8, frequency=0),
CANMessage(data_length=10, frequency=-100),
],
500000,
) == pytest.approx(0, rel=1e-2)

# bus overload
def test_bus_overload():
assert calculate_bus_load(
[
CANMessage(data_length=64, frequency=100),
@@ -29,29 +23,28 @@ def test_no_messages():
100000,
) == pytest.approx(138.72, rel=1e-5)
ManushPatell marked this conversation as resolved.
Show resolved Hide resolved

# high traffic - high frequency messages
def test_high_traffic():
assert calculate_bus_load(
[
CANMessage(data_length=8, frequency=1000),
CANMessage(data_length=4, frequency=800),
],
1000000,
) == pytest.approx(20.26, rel=1e-5)
) == pytest.approx(20.256, rel=1e-5)

# zero can speed
try:
def test_zero_speed():
with pytest.raises(ValueError):
assert calculate_bus_load(
[
CANMessage(data_length=8, frequency=1000),
CANMessage(data_length=4, frequency=800),
],
0,
) == pytest.approx(0, rel=1e-5)
except ZeroDivisionError:
print("Cannot divide by zero baud")

# negative can speed
assert (
def test_negative_speed():
with pytest.raises(ValueError):
assert (
calculate_bus_load(
[
CANMessage(data_length=8, frequency=1000),
@@ -60,6 +53,3 @@ def test_no_messages():
-500000,
)
) == pytest.approx(0, rel=1e-5)

# no message
assert (calculate_bus_load([], 500000)) == pytest.approx(0, rel=1e-5)
Loading