Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
john larson
16,594 Pointscould someone help clarify this function call from codeWars for me?
# I gather that a test is being done
# simultaneous with function being called,
# though I haven't seen it done like this before.
# Objective:
# find which number occurs an odd number of times.
# ...
# here is my question:
# what is the significance of the number 5
# outside the function call
# but still inside the assert_equals
# and:
# do I need to factor that in to the actual calculation
test.assert_equals(find_it([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]), 5)
2 Answers
Steven Parker
243,318 Points
I assume it is your job to implement find_it().
The purpose of the test.assert_equals() method is simply to help test your result by comparing it to another value. All it does is check if the values of both of its arguments are the same. In this case, the find_it() method is being tested with a particular array of values, and the correct solution for this set is the number 5 (since it appears 3 times in the set).
The following trivial example shows the function of assert_equals:
test.assert_equals(5, 5) # this would produce a "pass"
test.assert_equals(4, 5) # this would produce a "fail"
And no, you do not need to be concerned about this test fixture. Your challenge is strictly in implementing find_it() so that it will always generate the correct result for any data.
Bear in mind that typically on codewars, only simple test examples are provided. The actual tests done when you submit your program will involve much more complicated and extensive data sets.
john larson
16,594 PointsSteve, you mentioned codeWars a bit ago. I find their challenges great for making me look at things through a whole new lens. The challenges look simple at first, but they have interesting roadblocks to overcome in solving them. Thanks..
Seth Kroger
56,416 PointsIn testing there is always a function for asserting equality, usually of the form assertEqual(actual, expected) (or sometimes assertEqual(expected, actual)) with an optional failure message, though the name can vary with the language/testing framework. The code is the same as:
result = find_it([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5])
test.assert_equals(result, 5) # The result is expected to be 5.
john larson
16,594 Pointsjohn larson
16,594 PointsSeth and Steve, Thank you so much to both of you. That cleared it up for me. If I could give you both a best answer I would.