assert_equal hates my CPU

Discussion in 'Ruby' started by Phlip, Apr 14, 2005.

  1. Phlip

    Phlip Guest

    Rubies:

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

    def assert_equal(expected, actual, message=nil)
    full_message = build_message(message, <<EOT, expected, actual)
    <?> expected but was
    <?>.
    EOT
    assert_block(full_message) { expected == actual }
    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?

    def assert_equal(expected, actual, message=nil)
    assert_block(full_message) do
    if expected == actual then
    ''
    else
    build_message(message, <<EOT, expected, actual)
    <?> expected but was
    <?>.
    EOT
    end
    end
    end

    Then assert_block() should trigger if its block yields a complaint string.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Apr 14, 2005
    #1
    1. Advertising

  2. Phlip

    Saynatkari Guest

    Le 14/4/2005, "Phlip" <> a écrit:
    >Rubies:
    >
    >Here's the Ruby 1.8 test\unit version of assert_equal()
    >
    > def assert_equal(expected, actual, message=nil)
    > full_message = build_message(message, <<EOT, expected, actual)
    ><?> expected but was
    ><?>.
    >EOT
    > assert_block(full_message) { expected == actual }
    > 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?
    >
    > def assert_equal(expected, actual, message=nil)
    > assert_block(full_message) do
    > if expected == actual then
    > ''
    > else
    > build_message(message, <<EOT, expected, actual)
    ><?> expected but was
    ><?>.
    >EOT
    > end
    > end
    > 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

    --
    No-one expects the Solaris POSIX implementation!
     
    Saynatkari, Apr 14, 2005
    #2
    1. Advertising

  3. 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.


    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
    http://fhwang.net/
     
    Francis Hwang, Apr 14, 2005
    #3
  4. Phlip

    Phlip Guest

    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.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Apr 14, 2005
    #4
  5. Phlip

    Phlip Guest

    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
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Apr 14, 2005
    #5
  6. Phlip,

    On 4/13/05, Phlip <> wrote:
    > Because assertions passing should be the most common behavior, shouldn't
    > that method run like this?
    >
    > def assert_equal(expected, actual, message=nil)
    > assert_block(full_message) do
    > if expected == actual then
    > ''
    > else
    > build_message(message, <<EOT, expected, actual)
    > <?> expected but was
    > <?>.
    > EOT
    > end
    > end
    > 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
     
    Michael Walter, Apr 14, 2005
    #6
  7. 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
    >
    > http://industrialxp.org/community/bin/view/Main/
    > TestFirstUserInterfaces
    >
    >
    >
    >


    Francis Hwang
    http://fhwang.net/
     
    Francis Hwang, Apr 14, 2005
    #7
  8. Phlip

    Phlip Guest

    Phlip, Apr 14, 2005
    #8
  9. Phlip

    Phlip Guest

    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.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Apr 14, 2005
    #9
  10. Phlip,

    On 4/14/05, Phlip <> 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
     
    Michael Walter, Apr 14, 2005
    #10
  11. Phlip

    Eric Hodel Guest

    --Apple-Mail-1--145336091
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain; charset=US-ASCII; format=flowed

    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.


    Use the -n argument to the testrunner.

    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

    --Apple-Mail-1--145336091
    content-type: application/pgp-signature; x-mac-type=70674453;
    name=PGP.sig
    content-description: This is a digitally signed message part
    content-disposition: inline; filename=PGP.sig
    content-transfer-encoding: 7bit

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (Darwin)

    iEYEARECAAYFAkJd8xYACgkQMypVHHlsnwSteACeJyGCUCts7BLXqFtZTAc72Z1K
    mJAAnAwyfBSgemMbz/Uk5yQ//GJ0jayB
    =XkAS
    -----END PGP SIGNATURE-----

    --Apple-Mail-1--145336091--
     
    Eric Hodel, Apr 14, 2005
    #11
  12. Phlip

    Eric Hodel Guest

    --Apple-Mail-2--145137431
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed

    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?


    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

    --
    Eric Hodel - - http://segment7.net
    FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

    --Apple-Mail-2--145137431
    content-type: application/pgp-signature; x-mac-type=70674453;
    name=PGP.sig
    content-description: This is a digitally signed message part
    content-disposition: inline; filename=PGP.sig
    content-transfer-encoding: 7bit

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (Darwin)

    iEUEARECAAYFAkJd89wACgkQMypVHHlsnwSpnwCXUTAPGDmPYMqlupM4fjIzxM3e
    uACgz2bfys5bpfhTGNKIFjeI3RQR/FY=
    =6Mjq
    -----END PGP SIGNATURE-----

    --Apple-Mail-2--145137431--
     
    Eric Hodel, Apr 14, 2005
    #12
  13. Phlip

    Phlip Guest

    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...;)

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
     
    Phlip, Apr 14, 2005
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kasey

    Response.Redirect hates me

    Kasey, Oct 4, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    345
    Gozirra
    Oct 6, 2006
  2. hlinzhou

    windows hates signal?

    hlinzhou, Feb 10, 2006, in forum: C Programming
    Replies:
    8
    Views:
    515
    Michael Wojcik
    Feb 13, 2006
  3. Ari Brown

    My CPU Hates Me

    Ari Brown, Jul 6, 2007, in forum: Ruby
    Replies:
    4
    Views:
    135
    Ari Brown
    Jul 7, 2007
  4. Feng Tien
    Replies:
    4
    Views:
    112
    Dale Martenson
    Oct 24, 2007
  5. Ranieri Teixeira

    assert_equal problem

    Ranieri Teixeira, Feb 3, 2008, in forum: Ruby
    Replies:
    3
    Views:
    100
    Ranieri Teixeira
    Feb 4, 2008
Loading...

Share This Page