1

I have the following Eiffel code. I am doing test-driven-design with contracts.

check
    sorter.sorted (<<1>>).is_equal (<<1>>)
end

The code correctly detects that my sort returns the wrong value. However it would be nice to see what sorted returned. I can see that it is too late as is_equals consumes both values, and returns false, before the check throws the exception.

I have seen in other testing frameworks they have a special is_equal for the test framework. That allows better feedback. e.g.

check_equal(expected, value_under_test)

Is there anything like this in eiffel?

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52

2 Answers2

2

I would suggest looking at library testing. In particular, class EQA_COMMONLY_USED_ASSERTIONS has feature assert_equal that seems to do what you want to:

assert_equal (a_tag: READABLE_STRING_GENERAL; expected, actual: detachable ANY)
        -- Check that `expected ~ actual'.

The original example would then look like

assert_equal ("Is array sorted?", sorter.sorted (<<1>>), <<1>>)
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Yes I think it should work, unfortunately I can't get it to work. All sorts of errors with compatibility of concurrency of library and project. Every time I try to fix I just get another error. So it must be time to ask another question. But today I need a rest. – ctrl-alt-delor Jun 23 '20 at 18:30
  • @ctrl-alt-delor Please, tell the version number of your Eiffel compiler and concurrency settings of your project. – Alexander Kogtenkov Jun 23 '20 at 18:54
  • It is the latest, downloaded a few days ago (`Version = EiffelStudio 19.5 (19.05.10.3187 GPL Edition - linux-x86-64)`). The concurrency settings are SCOOP, I do not need them for what I am doing, so decided to set it to None. Bit this just creates other compile errors. Saying the precomp is not compatible. I can't work out how to resolve. – ctrl-alt-delor Jun 24 '20 at 09:58
  • @ctrl-alt-delor A quick solution would be to remove the precompile from your project (in the Project settings navigate to Target | Groups | Precompile and remove the nested node). Then you would need to [recompile the project from scratch](https://www.eiffel.org/doc/eiffelstudio/Clean_compile). – Alexander Kogtenkov Jun 24 '20 at 13:14
  • @ctrl-alt-delor Does it answer your question? If yes, it makes sense to mark the answer as accepted, if not, further questions are welcome. – Alexander Kogtenkov Jul 01 '20 at 16:06
0

Note that check statements are not "debug" statements: check statements are to ensure the correctness (i.e. trigger on errors), while debug statements help to understand what's going on. To debug your code once a check failed, you would add debug statements that output information before the check triggers.

ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52
U. Windl
  • 3,480
  • 26
  • 54