Skip to content

Commit

Permalink
Remove redundant logic
Browse files Browse the repository at this point in the history
  • Loading branch information
favrik committed Nov 5, 2016
1 parent 0ee3a93 commit 5b000fa
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lib/triangle_cases.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
class TriangleCase < OpenStruct
def test_name
initial = description.downcase
replaced = initial.gsub(/(true|false)/, replacements)
replaced = initial.gsub(/(true|false)/, expected_type)
if initial.eql?(replaced) && !initial.include?(triangle)
replaced = triangle + ' triangle ' + initial
end
'test_%s' % replaced.tr_s(', -', '_')
end

def replacements
booleans = { 'true' => '', 'false' => '' }
booleans.each { |k, v| booleans[k] = expected_type(k) }
end

def workload
[
"triangle = Triangle.new(#{sides})",
Expand All @@ -32,14 +27,8 @@ def failure_message
%Q("Expected '#{expected}', #{expected_type}.")
end

def expected_type(boolean = nil)
boolean ||= expected
"triangle is #{boolean_check(boolean) ? '' : 'not '}#{triangle}"
end

def boolean_check(boolean)
return true if boolean == true || boolean == 'true'
false
def expected_type
"triangle is #{expected ? '' : 'not '}#{triangle}"
end

def skipped
Expand Down

0 comments on commit 5b000fa

Please sign in to comment.