From 32c0ae2b75c6675930acebf5b243b7ad75f6029d Mon Sep 17 00:00:00 2001 From: AaronYoung5 Date: Thu, 27 Feb 2025 04:39:10 -0500 Subject: [PATCH] Updated negative condition logic/tests to not add 1000 for negative conditions --- test/test_unit_score_file.py | 23 +++++++++++------------ yadm | 3 ++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/test_unit_score_file.py b/test/test_unit_score_file.py index 7999810..f19c30d 100644 --- a/test/test_unit_score_file.py +++ b/test/test_unit_score_file.py @@ -326,20 +326,20 @@ def test_negative_class_condition(runner, yadm): """Test negative class condition: returns 0 when matching and proper score when not matching.""" script = f""" YADM_TEST=1 source {yadm} - score=0 local_class="testclass" local_classes=("testclass") # 0 + score=0 score_file "filename##~class.testclass" "dest" echo "score: $score" - # 1000 + 16 + # 16 score=0 score_file "filename##~class.badclass" "dest" echo "score2: $score" - # 0 + # 16 score=0 score_file "filename##~c.badclass" "dest" echo "score3: $score" @@ -348,24 +348,23 @@ def test_negative_class_condition(runner, yadm): assert run.success output = run.out.strip().splitlines() assert output[0] == "score: 0" - assert output[1] == "score2: 1016" - assert output[2] == "score3: 1016" + assert output[1] == "score2: 16" + assert output[2] == "score3: 16" def test_negative_combined_conditions(runner, yadm): """Test negative conditions for multiple alt types: returns 0 when matching and proper score when not matching.""" script = f""" YADM_TEST=1 source {yadm} - score=0 local_class="testclass" local_classes=("testclass") local_distro="testdistro" - # 0 + 0 = 0 + # (0) + (0) = 0 score=0 score_file "filename##~class.testclass,~distro.testdistro" "dest" echo "score: $score" - # 1000 * 2 + 16 + 4 = 2020 + # (1000 + 16) + (1000 + 4) = 2020 score=0 score_file "filename##class.testclass,distro.testdistro" "dest" echo "score2: $score" @@ -375,12 +374,12 @@ def test_negative_combined_conditions(runner, yadm): score_file "filename##~class.badclass,~distro.testdistro" "dest" echo "score3: $score" - # 1000 + 16 + 1000 + 4 = 2020 + # (1000 + 16) + (4) = 1020 score=0 score_file "filename##class.testclass,~distro.baddistro" "dest" echo "score4: $score" - # 1000 + 16 + 1000 + 16 = 2032 + # (1000 + 16) + (16) = 1032 score=0 score_file "filename##class.testclass,~class.badclass" "dest" echo "score5: $score" @@ -391,5 +390,5 @@ def test_negative_combined_conditions(runner, yadm): assert output[0] == "score: 0" assert output[1] == "score2: 2020" assert output[2] == "score3: 0" - assert output[3] == "score4: 2020" - assert output[4] == "score5: 2032" + assert output[3] == "score4: 1020" + assert output[4] == "score5: 1032" diff --git a/yadm b/yadm index fa5d550..0185115 100755 --- a/yadm +++ b/yadm @@ -242,7 +242,8 @@ function score_file() { score=0 return fi - score=$((score + 1000 + delta)) + (( negate )) || delta=$((delta + 1000)) + score=$((score + delta)) done record_score "$score" "$target" "$source" "$template_processor"