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.

Comments

4 Responses to “testing equality”

  1. Rab on September 24th, 2008 10:58 pm

    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!

  2. Rab on September 24th, 2008 10:58 pm

    My favorite line is the last one. Oh, and maybe the one before that too.

  3. Janissary on September 24th, 2008 11:20 pm

    KINDA QUIET IN HERE AINT IT?

    MAYBE IT’S BECAUSE I KILLED DERRICK.

  4. Rab on September 24th, 2008 11:28 pm

    I wouldn’t announce that here Jan. This site is… monitored.

Leave a Reply

You must be logged in to post a comment.

  • starting your head on fire

    Delivers oxygen to your brain faster than all other methods! Proven in double blind placebo controlled studies.

  • Places to Go

  • Blogroll

    • Cato @ Liberty - Cato is a libertarian research foundation. If you wish to stay informed on public policy, you can not ignore the Cato blog. Pay them a visit.
    • Greg Lincoln
    • Modo Vernant Omnia - Tampa local with many topics of interest to my readers. As you might imagine, I could not resist blogrolling a site that has tags as diverse as: economy (with views similar), spinning (as in wool), ancient Greek stuff, and occult.
    • Nassim Nicholas Taleb - Fooled by Randomness - The Economist turned me on to Mr. Taleb, a trader turned philoisopher (as described by Forbes). His writing and his thinking are quite interesting, and certainly more worthwhile than anything you will find here.
    • Ouralexander.org - Site discussing informed consent in pediatric medicine, by a family that experienced the worst possible tragedy.
    • RiskProf - An Insurance Blog - A truly marvelous blog. I know risk & insurance are less interesting to most of you than organizing your sock drawer, but this is excellent writing. Besides, if you understand insurance you have the right to complain about it.
    • Schneier on Security - This will be your favorite security blog. Bruce Schneier exposes “security theatre” and proposes realistic problems and solutions. Stay up to date on security policy and IT risk management with CRYPTOGRAM, his email newsletter.
    • The Goodly Mr. Plotkin - My excellent friend Richard Plotkin. Read his musings and insights, or wander through the social network of MySpace users. Several of his blog-friends are people I went to school or knew other ways… I wonder if they will Google me and say ‘hi.’
    • Worlds Healthiest Foods - I love this website. It is all about the nutritional value of foods that are considered ‘healthy,’ with tons of sources cited.