Skip to content

Instantly share code, notes, and snippets.

@Sabineth17
Created September 27, 2018 20:31
Show Gist options
  • Select an option

  • Save Sabineth17/c5a933655bc77e8e02897a737293aed9 to your computer and use it in GitHub Desktop.

Select an option

Save Sabineth17/c5a933655bc77e8e02897a737293aed9 to your computer and use it in GitHub Desktop.
Test_Writing_Exercise
require 'minitest/autorun'
require 'minitest/reporters'
require_relative 'flatten'
Minitest::Reporters.use!
describe "flatten_array" do
it "can be called with integers" do
#Arrange
array = [1,2,[3,nil],nil,5]
#Act up on that method
new_array = flatten_array(array)
#Assert that the output is
# expect(new_array).must_include Integers
expect(new_array).must_equal [1,2,3,5]
# Testing is about calling upon the method that we are trying to tests
# When we run the method 'the expect' is what we expect
# the result of calling the method will output
# Hence we call a specific value
end
it "can be called with string" do
array = ['John', 'Paula',['Mary',['Joy']]]
new_array = flatten_array(array)
# expect(new_array).must_include Strings
expect(new_array).must_equal ['John','Paula','Mary','Joy']
end
# Needs some work
it " can be called with mixed values" do
array = [1,3,nil,["Mary",["John"]]]
new_array = flatten_array(array)
# expect(new_array).must_include Strings and Integers
# expect(new_array).must_inclue Mixed Elements
expect(new_array).must_equal [1,3,'Mary','John']
end
it "will return a flattened array" do
array = [1,3,["Mary",nil,["John"]]]
new_array = flatten_array(array)
expect(new_array).must_equal [1,3,'Mary','John']
end
it "will return a flattened array" do
array = [[],[],[1]]
new_array = flatten_array(array)
expect(new_array).must_equal [1]
end
it "will not return nil as a value" do
array = [1,3,['Mary',nil,['John']]]
new_array = flatten_array(array)
# expect(new_array).wont_include nil
expect(new_array).must_equal [1,3,'Mary','John']
end
it "will return an empty array" do
array = [nil,nil,[nil,nil,[nil]]]
new_array = flatten_array(array)
# expect(new_array).wont_include nil
expect(new_array).must_equal [ ]
end
## Do edge case need to be argument errors?
## For example - all nils input - edge or argument error
### Raising Arguments -> when the expected output is incorrect. The output that the method was expecting is different than the output provided.
it "will raise an error when given an invalid argument" do
## no nested arrays
expect {flatten_array[1,2,3,'John','Paul',nil]}.must_raise ArgumentError
## all nils
expect {flatten_array[nil,nil,nil,[nil]]}.must_raise ArgumentError
## all empty arrays
expect {flatten_array[[],[],[]]}.must_raise ArgumentError
## no nil
expect {flatten_array[1,3,4,[5],"June","John"]}.must_raise ArgumentError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment