From db790e3ac55766ecb63dca11be5d75857590d11f Mon Sep 17 00:00:00 2001 From: Massimo Lauria Date: Wed, 30 Sep 2020 18:40:07 +0200 Subject: [PATCH] Fix random choice ofv coins --- cnfgen/clihelpers/simple_helpers.py | 3 +-- tests/test_randomcnf.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cnfgen/clihelpers/simple_helpers.py b/cnfgen/clihelpers/simple_helpers.py index bc6eab5b..bf5682b6 100644 --- a/cnfgen/clihelpers/simple_helpers.py +++ b/cnfgen/clihelpers/simple_helpers.py @@ -173,10 +173,9 @@ def build_cnf(args): n = args.n if args.plant: planted = {} - signs = random.choices([True, False], k=n) for i in range(n): - planted["x_{0}".format(i + 1)] = signs[i] + planted["x_{0}".format(i + 1)] = random.choice([True, False]) return RandomKCNF(args.k, args.n, diff --git a/tests/test_randomcnf.py b/tests/test_randomcnf.py index 2e12ae47..576d6c4f 100644 --- a/tests/test_randomcnf.py +++ b/tests/test_randomcnf.py @@ -65,6 +65,21 @@ def test_random_cnf_planted(): assert len(c) == 3 +def test_random_cnf_planted_2(): + planted = [{ + "x_1": True, + "x_2": False, + "x_3": True, + "x_4": False, + "x_5": True, + "x_6": True + }] + F = RandomKCNF(3, 6, 10, planted_assignments=planted) + for c in F: + assert len(c) == 3 + assert len(F) == 10 + + def test_randomkcnf_cnfgen(): cnfgen(["cnfgen", 'randkcnf', 4, 6, 10])