# Assert\_equal hates my CPU

**URL:** <https://rubytalk.org/t/assert-equal-hates-my-cpu/17644>\
**Category:** ruby-talk\
**Created:** [14 April 2005 03:09 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644 "2005-04-14T03:09:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 03:09 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/1 "2005-04-14T03:09:36Z")

</div>

Rubies:

Here's the Ruby 1.8 test\unit version of assert\_equal()

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def assert\_equal(expected, actual, message=nil)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;full\_message = build\_message(message, \<\<EOT, expected, actual)  
\<?\> expected but was  
\<?\>.  
EOT  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_block(full\_message) { expected == actual }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Notice it builds a message even if the assertion passes.

Because assertions passing should be the most common behavior, shouldn't  
that method run like this?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def assert\_equal(expected, actual, message=nil)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_block(full\_message) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if expected == actual then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build\_message(message, \<\<EOT, expected, actual)  
\<?\> expected but was  
\<?\>.  
EOT  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Then assert\_block() should trigger if its block yields a complaint string.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)

---

<div class="post-metadata">

**Author:** ![Anonymous\_Coward](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Anonymous\_Coward](https://rubytalk.org/u/Anonymous_Coward)\
**Post date:** [14 April 2005 03:21 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/2 "2005-04-14T03:21:16Z")

</div>

> Rubies:
> 
> Here's the Ruby 1.8 test\unit version of assert\_equal()
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def assert\_equal(expected, actual, message=nil)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;full\_message = build\_message(message, \<\<EOT, expected, actual)  
> \<?\> expected but was  
> \<?\>.  
> EOT  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_block(full\_message) { expected == actual }  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> Notice it builds a message even if the assertion passes.
> 
> Because assertions passing should be the most common behavior, shouldn't  
> that method run like this?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def assert\_equal(expected, actual, message=nil)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_block(full\_message) do  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if expected == actual then  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build\_message(message, \<\<EOT, expected, actual)  
> \<?\> expected but was  
> \<?\>.  
> EOT  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end
> 
> Then assert\_block() should trigger if its block yields a complaint string.

test/unit has a built-in load tester 🙂

Yes, it would make more sense the other way but  
I suspect this is due to simpler implementation  
and the idea that assertions do not run in production  
code so it does not matter. I can not test it  
right now but it does not seem like your code  
would actually run since 'full\_message' does  
not exist?

> Phlip

E

> **···**
>
> Le 14/4/2005, "Phlip" \<phlip\_cpp@yahoo.com\> a écrit:
> 
> --  
> No-one expects the Solaris POSIX implementation!

---

<div class="post-metadata">

**Author:** ![Michael\_Walter1](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Michael\_Walter1](https://rubytalk.org/u/Michael_Walter1)\
**Post date:** [14 April 2005 04:06 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/3 "2005-04-14T04:06:02Z")

</div>

Phlip,

> Because assertions passing should be the most common behavior, shouldn't  
> that method run like this?
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def assert\_equal(expected, actual, message=nil)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_block(full\_message) do  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if expected == actual then  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;''  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;build\_message(message, \<\<EOT, expected, actual)  
> \<?\> expected but was  
> \<?\>.  
> EOT  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Unbound variable 'full\_message'? :\

> Then assert\_block() should trigger if its block yields a complaint string.

That's too much magic in the block semantics for me. Without taking a  
look into the test sources, mayb you could call some  
raise\_error(reason) function instead?

Regards,  
Michael

> **···**
>
> On 4/13/05, Phlip \<phlip\_cpp@yahoo.com\> wrote:

---

<div class="post-metadata">

**Author:** ![Francis\_Hwang1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Francis\_Hwang1](https://rubytalk.org/u/Francis_Hwang1)\
**Post date:** [14 April 2005 03:25 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/4 "2005-04-14T03:25:57Z")

</div>

Ah, but it can matter, can't it? If you're running a codebase with, say, 500+ unit tests and 1900+ assertions (hell, I'm running one right now), these things can add up. And when your tests are slow, you'll run them less often ...

Francis Hwang

> **[fhwang - Overview](https://github.com/fhwang/)**
>
> fhwang has 66 repositories available. Follow their code on GitHub.

> **···**
>
> On Apr 13, 2005, at 11:21 PM, Saynatkari wrote:
> 
> > I suspect this is due to simpler implementation  
> > and the idea that assertions do not run in production  
> > code so it does not matter.

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 03:48 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/5 "2005-04-14T03:48:17Z")

</div>

Saynatkari wrote:

> test/unit has a built-in load tester 🙂

Do you mean the profiler?

Otherwise, where do I Google?

> Yes, it would make more sense the other way but  
> I suspect this is due to simpler implementation  
> and the idea that assertions do not run in production  
> code so it does not matter. I can not test it  
> right now but it does not seem like your code  
> would actually run since 'full\_message' does  
> not exist?

I want my tests to run in \<5 seconds. Otherwise I get bored, drift off,  
start downloading comics, etc.

> No-one expects the Solaris POSIX implementation!

Whip me. Beat me. Make me install Oracle.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 04:14 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/6 "2005-04-14T04:14:37Z")

</div>

Michael Walter wrote:

> That's too much magic in the block semantics for me.

I think my question is visible beyond the minor typos.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 03:59 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/7 "2005-04-14T03:59:37Z")

</div>

Francis Hwang wrote:

> Ah, but it can matter, can't it? If you're running a codebase with,  
> say, 500+ unit tests and 1900+ assertions (hell, I'm running one right  
> now), these things can add up. And when your tests are slow, you'll run  
> them less often ...

How long do your tests take?

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)

---

<div class="post-metadata">

**Author:** ![Michael\_Walter1](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@Michael\_Walter1](https://rubytalk.org/u/Michael_Walter1)\
**Post date:** [14 April 2005 04:32 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/8 "2005-04-14T04:32:08Z")

</div>

Phlip,

> **···**
>
> On 4/14/05, Phlip \<phlip\_cpp@yahoo.com\> wrote:
> 
> > Michael Walter wrote:
> > 
> > \> That's too much magic in the block semantics for me.
> > 
> > I think my question is visible beyond the minor typos.
> 
> The comment (as detailed in the remainder you snipped) is not about typos.
> 
> Regards,  
> Michael

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [14 April 2005 04:36 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/9 "2005-04-14T04:36:06Z")

</div>

Use the -n argument to the testrunner.

[PGP.sig](https://rubytalk.org/uploads/short-url/vddg2PwachCYZWcAqAjLPxPgcEJ.sig) (194 Bytes)

> **···**
>
> On 13 Apr 2005, at 20:48, Phlip wrote:
> 
> > Saynatkari wrote:
> > 
> > > test/unit has a built-in load tester 🙂
> > 
> > Do you mean the profiler?
> > 
> > Otherwise, where do I Google?
> > 
> > > Yes, it would make more sense the other way but  
> > > I suspect this is due to simpler implementation  
> > > and the idea that assertions do not run in production  
> > > code so it does not matter. I can not test it  
> > > right now but it does not seem like your code  
> > > would actually run since 'full\_message' does  
> > > not exist?
> > 
> > I want my tests to run in \<5 seconds. Otherwise I get bored, drift off,  
> > start downloading comics, etc.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Francis\_Hwang1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@Francis\_Hwang1](https://rubytalk.org/u/Francis_Hwang1)\
**Post date:** [14 April 2005 04:07 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/10 "2005-04-14T04:07:01Z")

</div>

120 seconds, give or take, when I run the whole suite. This is one of the reasons I'm always looking for chunks of code to extract into their own libs; you decrease cohesion, and accordingly you decrease the combinatorial space your tests have to deal with.

> **···**
>
> On Apr 13, 2005, at 11:59 PM, Phlip wrote:
> 
> > Francis Hwang wrote:
> > 
> > > Ah, but it can matter, can't it? If you're running a codebase with,  
> > > say, 500+ unit tests and 1900+ assertions (hell, I'm running one right  
> > > now), these things can add up. And when your tests are slow, you'll run  
> > > them less often ...
> > 
> > How long do your tests take?
> > 
> > -- Phlip  
> > &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)
> 
> Francis Hwang
> 
> > **[fhwang - Overview](https://github.com/fhwang/)**
> >
> > fhwang has 66 repositories available. Follow their code on GitHub.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [14 April 2005 04:39 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/11 "2005-04-14T04:39:14Z")

</div>

It depends on what I'm working on. If I want to check in:

$ time make  
ruby -w -I.:../../ParseTree/dev/lib:../../ParseTree/dev/test test\_all.rb  
Loaded suite test\_all  
Started  
....................................................................................................................................................................................................................................................................................................................................................................  
Finished in 4.749234 seconds.

356 tests, 714 assertions, 0 failures, 0 errors

real 0m5.916s  
user 0m4.400s  
sys 0m0.150s

If I'm working on just one thing:

$ time ruby -w -I.:../../ParseTree/dev/lib:../../ParseTree/dev/test test\_all.rb -n /test\_iteration/  
Loaded suite test\_all  
Started  
........................  
Finished in 0.448557 seconds.

24 tests, 72 assertions, 0 failures, 0 errors

real 0m1.677s  
user 0m1.300s  
sys 0m0.130s

[PGP.sig](https://rubytalk.org/uploads/short-url/3512eGY0sLAOI5WaIMCgutE3UOK.sig) (194 Bytes)

> **···**
>
> On 13 Apr 2005, at 20:59, Phlip wrote:
> 
> > Francis Hwang wrote:
> > 
> > > Ah, but it can matter, can't it? If you're running a codebase with,  
> > > say, 500+ unit tests and 1900+ assertions (hell, I'm running one right  
> > > now), these things can add up. And when your tests are slow, you'll run  
> > > them less often ...
> > 
> > How long do your tests take?
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 18:14 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/12 "2005-04-14T18:14:35Z")

</div>

Michael Walter wrote:

> The comment (as detailed in the remainder you snipped) is not about typos.

That was pseudo-code.

Thanks everyone for the tips; I have a bead on the problem now. This group  
has an excellent test infection.

(Don'cha just love asking questions about VBunit on a VB newsgroup? If blank  
stares were a dime each...😉

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [14 April 2005 04:19 UTC](https://rubytalk.org/t/assert-equal-hates-my-cpu/17644/13 "2005-04-14T04:19:36Z")

</div>

Francis Hwang wrote:

> 120 seconds, give or take, when I run the whole suite. This is one of  
> the reasons I'm always looking for chunks of code to extract into their  
> own libs; you decrease cohesion, and accordingly you decrease the  
> combinatorial space your tests have to deal with.

Ah, I'm looking at a much lower ratio of cases to seconds. So profiling and  
optimizing is now more important than incremental testing.

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)
