testing equality
Posted on September 24, 2008
Filed Under In all seriousness, Programming, Uncategorized |
You know, they say Ruby is a great language for testers, and I am finding this to be true. Earlier today I was able to test the state of reality itself using Ruby, and now I have devised a test for equality.
First, let’s examine equality:
def equality(x=0, y=0)
tellxy = " ( x = " +x.to_s + ", y = " + y.to_s + " )"
if x == y: puts "x is equal to y" + tellxy
puts "The dream of equality is achieved!"
elsif x > y: puts "x is greater than y" + tellxy
elsif x < y: puts "x is less than than y" + tellxy end
puts "Alas, no equality." unless x == y
end
Not too complicated right? Everything starts off equal, and we know that either x or y has gained an advantage because we get a “greater than” message followed by a lament.
Now let’s get to the nitty gritty of equality using more Ruby. The easiest test against all possible scenarios might look something like this:
def test_equality
for x in -5..5
for y in -5..5
equality(x, y)
end
end
end
But that gives us a lot of output doesn’t it? Wanna see the output? I will post it in a comment to keep from cluttering up the page.
Let’s devise a slightly less thorough test, since the other is so much to swallow at once. Think “standardized test” here… like any standardized test, we want to boil the results down to something we can read and use to decide if our system is working:
def test_equality2
yrange = (-5..5).to_a.reverse
z = 0
for x in -5..5
y = yrange.at(z)
equality(x, y)
z += 1
end
end
There we go! We ended up with a slightly more complex system, but maybe the results are worthwhile. Let’s see what we have determined about the function of equality here. This is the output:
x is less than than y ( x = -5, y = 5 )
Alas, no equality.
x is less than than y ( x = -4, y = 4 )
Alas, no equality.
x is less than than y ( x = -3, y = 3 )
Alas, no equality.
x is less than than y ( x = -2, y = 2 )
Alas, no equality.
x is less than than y ( x = -1, y = 1 )
Alas, no equality.
x is equal to y ( x = 0, y = 0 )
The dream of equality is achieved!
x is greater than y ( x = 1, y = -1 )
Alas, no equality.
x is greater than y ( x = 2, y = -2 )
Alas, no equality.
x is greater than y ( x = 3, y = -3 )
Alas, no equality.
x is greater than y ( x = 4, y = -4 )
Alas, no equality.
x is greater than y ( x = 5, y = -5 )
Alas, no equality.
Isn’t that lovely. As promised, I will post the output for test_equality in the comments. Happy day to you.
Here is the output we have all been waiting for… the amazing test_equality:
x is equal to y ( x = -5, y = -5 )
The dream of equality is achieved!
x is less than than y ( x = -5, y = -4 )
Alas, no equality.
x is less than than y ( x = -5, y = -3 )
Alas, no equality.
x is less than than y ( x = -5, y = -2 )
Alas, no equality.
x is less than than y ( x = -5, y = -1 )
Alas, no equality.
x is less than than y ( x = -5, y = 0 )
Alas, no equality.
x is less than than y ( x = -5, y = 1 )
Alas, no equality.
x is less than than y ( x = -5, y = 2 )
Alas, no equality.
x is less than than y ( x = -5, y = 3 )
Alas, no equality.
x is less than than y ( x = -5, y = 4 )
Alas, no equality.
x is less than than y ( x = -5, y = 5 )
Alas, no equality.
x is greater than y ( x = -4, y = -5 )
Alas, no equality.
x is equal to y ( x = -4, y = -4 )
The dream of equality is achieved!
x is less than than y ( x = -4, y = -3 )
Alas, no equality.
x is less than than y ( x = -4, y = -2 )
Alas, no equality.
x is less than than y ( x = -4, y = -1 )
Alas, no equality.
x is less than than y ( x = -4, y = 0 )
Alas, no equality.
x is less than than y ( x = -4, y = 1 )
Alas, no equality.
x is less than than y ( x = -4, y = 2 )
Alas, no equality.
x is less than than y ( x = -4, y = 3 )
Alas, no equality.
x is less than than y ( x = -4, y = 4 )
Alas, no equality.
x is less than than y ( x = -4, y = 5 )
Alas, no equality.
x is greater than y ( x = -3, y = -5 )
Alas, no equality.
x is greater than y ( x = -3, y = -4 )
Alas, no equality.
x is equal to y ( x = -3, y = -3 )
The dream of equality is achieved!
x is less than than y ( x = -3, y = -2 )
Alas, no equality.
x is less than than y ( x = -3, y = -1 )
Alas, no equality.
x is less than than y ( x = -3, y = 0 )
Alas, no equality.
x is less than than y ( x = -3, y = 1 )
Alas, no equality.
x is less than than y ( x = -3, y = 2 )
Alas, no equality.
x is less than than y ( x = -3, y = 3 )
Alas, no equality.
x is less than than y ( x = -3, y = 4 )
Alas, no equality.
x is less than than y ( x = -3, y = 5 )
Alas, no equality.
x is greater than y ( x = -2, y = -5 )
Alas, no equality.
x is greater than y ( x = -2, y = -4 )
Alas, no equality.
x is greater than y ( x = -2, y = -3 )
Alas, no equality.
x is equal to y ( x = -2, y = -2 )
The dream of equality is achieved!
x is less than than y ( x = -2, y = -1 )
Alas, no equality.
x is less than than y ( x = -2, y = 0 )
Alas, no equality.
x is less than than y ( x = -2, y = 1 )
Alas, no equality.
x is less than than y ( x = -2, y = 2 )
Alas, no equality.
x is less than than y ( x = -2, y = 3 )
Alas, no equality.
x is less than than y ( x = -2, y = 4 )
Alas, no equality.
x is less than than y ( x = -2, y = 5 )
Alas, no equality.
x is greater than y ( x = -1, y = -5 )
Alas, no equality.
x is greater than y ( x = -1, y = -4 )
Alas, no equality.
x is greater than y ( x = -1, y = -3 )
Alas, no equality.
x is greater than y ( x = -1, y = -2 )
Alas, no equality.
x is equal to y ( x = -1, y = -1 )
The dream of equality is achieved!
x is less than than y ( x = -1, y = 0 )
Alas, no equality.
x is less than than y ( x = -1, y = 1 )
Alas, no equality.
x is less than than y ( x = -1, y = 2 )
Alas, no equality.
x is less than than y ( x = -1, y = 3 )
Alas, no equality.
x is less than than y ( x = -1, y = 4 )
Alas, no equality.
x is less than than y ( x = -1, y = 5 )
Alas, no equality.
x is greater than y ( x = 0, y = -5 )
Alas, no equality.
x is greater than y ( x = 0, y = -4 )
Alas, no equality.
x is greater than y ( x = 0, y = -3 )
Alas, no equality.
x is greater than y ( x = 0, y = -2 )
Alas, no equality.
x is greater than y ( x = 0, y = -1 )
Alas, no equality.
x is equal to y ( x = 0, y = 0 )
The dream of equality is achieved!
x is less than than y ( x = 0, y = 1 )
Alas, no equality.
x is less than than y ( x = 0, y = 2 )
Alas, no equality.
x is less than than y ( x = 0, y = 3 )
Alas, no equality.
x is less than than y ( x = 0, y = 4 )
Alas, no equality.
x is less than than y ( x = 0, y = 5 )
Alas, no equality.
x is greater than y ( x = 1, y = -5 )
Alas, no equality.
x is greater than y ( x = 1, y = -4 )
Alas, no equality.
x is greater than y ( x = 1, y = -3 )
Alas, no equality.
x is greater than y ( x = 1, y = -2 )
Alas, no equality.
x is greater than y ( x = 1, y = -1 )
Alas, no equality.
x is greater than y ( x = 1, y = 0 )
Alas, no equality.
x is equal to y ( x = 1, y = 1 )
The dream of equality is achieved!
x is less than than y ( x = 1, y = 2 )
Alas, no equality.
x is less than than y ( x = 1, y = 3 )
Alas, no equality.
x is less than than y ( x = 1, y = 4 )
Alas, no equality.
x is less than than y ( x = 1, y = 5 )
Alas, no equality.
x is greater than y ( x = 2, y = -5 )
Alas, no equality.
x is greater than y ( x = 2, y = -4 )
Alas, no equality.
x is greater than y ( x = 2, y = -3 )
Alas, no equality.
x is greater than y ( x = 2, y = -2 )
Alas, no equality.
x is greater than y ( x = 2, y = -1 )
Alas, no equality.
x is greater than y ( x = 2, y = 0 )
Alas, no equality.
x is greater than y ( x = 2, y = 1 )
Alas, no equality.
x is equal to y ( x = 2, y = 2 )
The dream of equality is achieved!
x is less than than y ( x = 2, y = 3 )
Alas, no equality.
x is less than than y ( x = 2, y = 4 )
Alas, no equality.
x is less than than y ( x = 2, y = 5 )
Alas, no equality.
x is greater than y ( x = 3, y = -5 )
Alas, no equality.
x is greater than y ( x = 3, y = -4 )
Alas, no equality.
x is greater than y ( x = 3, y = -3 )
Alas, no equality.
x is greater than y ( x = 3, y = -2 )
Alas, no equality.
x is greater than y ( x = 3, y = -1 )
Alas, no equality.
x is greater than y ( x = 3, y = 0 )
Alas, no equality.
x is greater than y ( x = 3, y = 1 )
Alas, no equality.
x is greater than y ( x = 3, y = 2 )
Alas, no equality.
x is equal to y ( x = 3, y = 3 )
The dream of equality is achieved!
x is less than than y ( x = 3, y = 4 )
Alas, no equality.
x is less than than y ( x = 3, y = 5 )
Alas, no equality.
x is greater than y ( x = 4, y = -5 )
Alas, no equality.
x is greater than y ( x = 4, y = -4 )
Alas, no equality.
x is greater than y ( x = 4, y = -3 )
Alas, no equality.
x is greater than y ( x = 4, y = -2 )
Alas, no equality.
x is greater than y ( x = 4, y = -1 )
Alas, no equality.
x is greater than y ( x = 4, y = 0 )
Alas, no equality.
x is greater than y ( x = 4, y = 1 )
Alas, no equality.
x is greater than y ( x = 4, y = 2 )
Alas, no equality.
x is greater than y ( x = 4, y = 3 )
Alas, no equality.
x is equal to y ( x = 4, y = 4 )
The dream of equality is achieved!
x is less than than y ( x = 4, y = 5 )
Alas, no equality.
x is greater than y ( x = 5, y = -5 )
Alas, no equality.
x is greater than y ( x = 5, y = -4 )
Alas, no equality.
x is greater than y ( x = 5, y = -3 )
Alas, no equality.
x is greater than y ( x = 5, y = -2 )
Alas, no equality.
x is greater than y ( x = 5, y = -1 )
Alas, no equality.
x is greater than y ( x = 5, y = 0 )
Alas, no equality.
x is greater than y ( x = 5, y = 1 )
Alas, no equality.
x is greater than y ( x = 5, y = 2 )
Alas, no equality.
x is greater than y ( x = 5, y = 3 )
Alas, no equality.
x is greater than y ( x = 5, y = 4 )
Alas, no equality.
x is equal to y ( x = 5, y = 5 )
The dream of equality is achieved!
My favorite line is the last one. Oh, and maybe the one before that too.
KINDA QUIET IN HERE AINT IT?
MAYBE IT’S BECAUSE I KILLED DERRICK.
I wouldn’t announce that here Jan. This site is… monitored.