Skip to content

Commit

Permalink
#51 and, or, not
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 2, 2024
1 parent 9b7345c commit 6a88af4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/fbe/award.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def calc(bill)
bill.points
when :if
to_val(@operands[0], bill) ? to_val(@operands[1], bill) : to_val(@operands[2], bill)
when :and
@operands.all? { |o| to_val(o, bill) }
when :or
@operands.any? { |o| to_val(o, bill) }
when :not
!to_val(@operands[0], bill)
when :eq
to_val(@operands[0], bill) == to_val(@operands[1], bill)
when :lt
Expand Down Expand Up @@ -150,7 +156,6 @@ def calc(bill)
b = to_val(@operands[2], bill)
min, max = [a, b].minmax
return 0 if (!v.negative? && v < min) || (!v.positive? && v > max)

v.clamp(min, max)
else
raise "Unknown term '#{@op}'"
Expand All @@ -171,6 +176,12 @@ def to_s
'total'
when :if
"if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}"
when :and
@operands.map(&:to_s).join(' and ')
when :or
@operands.map(&:to_s).join(' or ')
when :not
"not #{@operands[0]}"
when :eq
"#{to_p(@operands[0])} = #{to_p(@operands[1])}"
when :lt
Expand Down
7 changes: 6 additions & 1 deletion test/fbe/test_award.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def test_simple
(give basis "as a basis")
(let fee 10)
(aka
(set b1 (if (lt hours max) fee 0))
(set b1
(if
(and
(lt hours max)
(not (eq hours 0)))
fee 0))
(give b1 "for resolving the bug in ${hours} (<${max}) hours")
"add ${+fee} if it was resolved in less than ${max} hours")
(set days (div hours 24))
Expand Down

0 comments on commit 6a88af4

Please sign in to comment.