Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
serradura committed Jan 29, 2024
1 parent f57a45e commit 3a363dc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ class Division

private

ValidNumber = ->(arg) { arg.is_a?(Numeric) && arg != Float::NAN && arg != Float::INFINITY }
ValidNumber = ->(arg) { arg.is_a?(Numeric) && (!arg.respond_to?(:finite?) || arg.finite?) }

def require_numbers((arg1, arg2))
ValidNumber[arg1] or return Failure(:invalid_arg, 'arg1 must be a valid number')
Expand Down
43 changes: 43 additions & 0 deletions test/bcdd/result/config/feature/transitions_listener_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'test_helper'

class BCDD::Result::Config
class FeatureTransitionsListenerTest < Minitest::Test
class Division
include BCDD::Result.mixin(config: { addon: { continue: true } })

def call(arg1, arg2)
BCDD::Result.transitions(name: 'Division') do
Given([arg1, arg2])
.and_then(:require_numbers)
.and_then(:check_for_zeros)
.and_then(:divide)
end
end

private

ValidNumber = ->(arg) { arg.is_a?(Numeric) && (!arg.respond_to?(:finite?) || arg.finite?) }

def require_numbers((arg1, arg2))
ValidNumber[arg1] or return Failure(:invalid_arg, 'arg1 must be a valid number')
ValidNumber[arg2] or return Failure(:invalid_arg, 'arg2 must be a valid number')

Continue([arg1, arg2])
end

def check_for_zeros(numbers)
num1, num2 = numbers

return Failure(:division_by_zero, 'num2 cannot be zero') if num2.zero?

num1.zero? ? Success(:division_completed, 0) : Continue(numbers)
end

def divide((num1, num2))
Success(:division_completed, num1 / num2)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call(arg1, arg2)

private

ValidNumber = ->(arg) { arg.is_a?(Numeric) && arg != Float::NAN && arg != Float::INFINITY }
ValidNumber = ->(arg) { arg.is_a?(Numeric) && (!arg.respond_to?(:finite?) || arg.finite?) }

def require_numbers(arg1, arg2)
ValidNumber[arg1] or return Failure(:invalid_arg, 'arg1 must be a valid number')
Expand Down

0 comments on commit 3a363dc

Please sign in to comment.