Skip to content

Commit

Permalink
write test cases for multipy program and vowel checker
Browse files Browse the repository at this point in the history
  • Loading branch information
rabajaj0509 committed May 17, 2018
1 parent 88792a2 commit 3a6aaa7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Understanding assertions/Vowel Checker/test_vowels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'minitest/autorun'

module MiniTest::Assertions
def assert_vowel(letter)
assert %w(a e i o u).include?(letter), "Expected #{letter} to be a vowel"
end
end

describe 'Vowel Checker' do
%w(a e i o u).each do |letter|
it "#{letter} is a vowel" do
assert_vowel letter
end
end
end
5 changes: 5 additions & 0 deletions Understanding assertions/Vowel Checker/vowels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class String
def vowel?
%w(a e i o u).include?(self)
end
end
17 changes: 17 additions & 0 deletions Understanding assertions/multiply/multiply.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Multiply
def multiply(x, y)
x * y
end

def multi_multiply(number)
total = 1
if number == 0
puts 'Can not find a valid multiple'
else
(1..number).each do |i|
total *= i
end
end
total
end
end
16 changes: 16 additions & 0 deletions Understanding assertions/multiply/test_multiply.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'minitest/autorun'
require_relative 'multiply'

class MutiplyTest < Minitest::Test
def test_multiplication
operation = Multiply.new
result = operation.multiply(3, 3)
assert_equal 9, result
end

def test_mutiplication_of_n_numbers
nnumbers = Multiply.new
result = nnumbers.multi_multiply(8)
assert_equal 40320, result
end
end

0 comments on commit 3a6aaa7

Please sign in to comment.