diff --git a/library/src/iqb/calculator.py b/library/src/iqb/calculator.py index e9f5611..4fb1ed9 100644 --- a/library/src/iqb/calculator.py +++ b/library/src/iqb/calculator.py @@ -79,20 +79,9 @@ def calculate_binary_requirement_score(self, network_requirement, value, thresho f"The binary requirement score method is not implemented for the network_requirement: {network_requirement}" ) - def calculate_iqb_score(self, data=None, print_details=False): + def calculate_iqb_score(self, data, print_details=False): """Calculates IQB score based on given data.""" - # TODO(bassosimone): remove the default data sample in a subsequent interation. - sample_data = { - "m-lab": { - "download_throughput_mbps": 15, - "upload_throughput_mbps": 20, - "latency_ms": 75, - "packet_loss": 0.007, - } - } - data = sample_data if data is None else data - # TODO(bassosimone): remove printing from the current function and instead # add more tests to gain better confidence about it being WAI doprint = print if print_details else lambda *args, **kwargs: None diff --git a/library/tests/iqb/calculator_test.py b/library/tests/iqb/calculator_test.py index 9a11762..aace54d 100644 --- a/library/tests/iqb/calculator_test.py +++ b/library/tests/iqb/calculator_test.py @@ -90,41 +90,42 @@ def test_invalid_network_requirement_raises_error(self): class TestIQBCalculatorScoreCalculation: """Tests for IQBCalculator score calculation.""" + _SAMPLE_DATA = { + "m-lab": { + "download_throughput_mbps": 15, + "upload_throughput_mbps": 20, + "latency_ms": 75, + "packet_loss": 0.007, + } + } + def test_calculate_iqb_score_default_data(self): - """Test that IQBCalculator score can be calculated with default data.""" + """Test that IQBCalculator score can be calculated with explicit input data.""" iqb = IQBCalculator(name="test1") - score = iqb.calculate_iqb_score() + score = iqb.calculate_iqb_score(data=self._SAMPLE_DATA) # The score should be a float between 0 and 1 assert isinstance(score, (int, float)) assert 0 <= score <= 1 def test_calculate_iqb_score_with_custom_data(self): - """Test that passing custom data raises NotImplementedError.""" - iqb = IQBCalculator() - sample_data = { - "m-lab": { - "download_throughput_mbps": 15, - "upload_throughput_mbps": 20, - "latency_ms": 75, - "packet_loss": 0.007, - } - } - score = iqb.calculate_iqb_score(data=sample_data) + """Test that IQBCalculator score can be calculated with custom data.""" + iqb = IQBCalculator() + score = iqb.calculate_iqb_score(data=self._SAMPLE_DATA) assert isinstance(score, (int, float)) assert 0 <= score <= 1 def test_calculate_iqb_score_print_details(self): """Test that IQBCalculator score calculation works with print_details=True.""" iqb = IQBCalculator() - score = iqb.calculate_iqb_score(print_details=True) + score = iqb.calculate_iqb_score(data=self._SAMPLE_DATA, print_details=True) assert isinstance(score, (int, float)) assert 0 <= score <= 1 def test_calculate_iqb_score_consistency(self): """Test that IQBCalculator score calculation is consistent across calls.""" iqb = IQBCalculator() - score1 = iqb.calculate_iqb_score() - score2 = iqb.calculate_iqb_score() + score1 = iqb.calculate_iqb_score(data=self._SAMPLE_DATA) + score2 = iqb.calculate_iqb_score(data=self._SAMPLE_DATA) assert score1 == score2