| ▲ | tayo42 8 hours ago | |
Idk how exactly to do it in cpp becasue I'm not familiar with the tooling You could write a test that makes sure the output of someCall is passed directly to printeven without being modified. The example as you wrote is hard to test in general. It's probably not something you would write if your serious about testing. | ||
| ▲ | shagie 7 hours ago | parent [-] | |
In C++, the code would look like:
---Nothing in there is wrong. There is no test that would fail short of going through the hassle of creating a new type that does some sort of introspection of its call stack to verify which function its being called in. Likewise, identify if a linter or other static analysis tool could catch this issue. Yes, this is a contrived example and it likely isn't idiomatic C++ (C++ isn't my 'native' language). The actual code in Java was more complex and had a lot more going on in other parts of the files. However, it should serve to show that there isn't a test for printEvens or someCall that would fail because it was filtered twice. Additionally, it should show that a linter or other static analysis wouldn't catch the problem (I would be rather impressed with one that did). From ChatGPT a code review of the code: https://chatgpt.com/share/69780ce6-03e0-8011-a488-e9f3f8173f... | ||