From 6559bcd19450c20f6c9df31e782efc98e28cc85b Mon Sep 17 00:00:00 2001 From: lola Date: Wed, 22 Oct 2025 10:44:33 -0700 Subject: [PATCH] add error cases for random in filter lambdas --- tests/syntax/test_distributions.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/syntax/test_distributions.py b/tests/syntax/test_distributions.py index 62acfe939..fbfa81073 100644 --- a/tests/syntax/test_distributions.py +++ b/tests/syntax/test_distributions.py @@ -510,6 +510,31 @@ def test_list_filtered_empty_2(): assert sum(v == 2 for v in vs) >= 85 +def test_filter_lambda_random_global(): + scenario = compileScenic( + """ + thresh = Range(0, 1) + mylist = [Range(-1, 1), Range(2, 3)] + filtered = filter(lambda v: v > thresh, mylist) + ego = new Object with foo Uniform(*filtered) + """ + ) + with pytest.raises(RandomControlFlowError): + sampleEgo(scenario) + + +def test_filter_lambda_random_threshold(): + scenario = compileScenic( + """ + mylist = [Range(-1, 1), Range(3, 4)] + filtered = filter(lambda v: v > Range(0, 1), mylist) + ego = new Object with foo Uniform(*filtered) + """ + ) + with pytest.raises(RandomControlFlowError): + sampleEgo(scenario) + + def test_tuple(): scenario = compileScenic("ego = new Object with foo tuple([3, Uniform(1, 2)])") ts = [sampleEgo(scenario).foo for i in range(60)]