[riot-notifications] [RIOT-OS/RIOT] tests/thread_float: improve and add script (#16901)

Martine Lenders notifications at github.com
Tue Sep 28 22:05:20 CEST 2021


@miri64 commented on this pull request.



> +
+    child.expect(r"t(\d): (\d{3}\.\d+)")
+    first_thread = int(child.match.group(1))
+    first_result = float(child.match.group(2))
+    assert (first_result > 141.4) and (first_result < 141.5), f"result of t{first_thread} wrong"
+    child.expect(r"t(\d): (\d{3}\.\d+)")
+    second_thread = int(child.match.group(1))
+    second_result = float(child.match.group(2))
+    assert (second_result > 141.4) and (second_result < 141.5), f"result of t{second_thread} wrong"
+    assert (first_thread == 1) or (first_thread == 3), "only thread t1 and t3 should print"
+    assert (second_thread == 1) or (second_thread == 3), "only thread t1 and t3 should print"
+    assert first_thread != second_thread, "t1 and t3 should print in turns"
+    for _ in range(3):
+        child.expect(r"t(\d): (\d{3}\.\d+)")
+        assert first_thread == int(child.match.group(1)), "t1 and t3 should print in turns"
+        assert first_result == float(child.match.group(2)), "same calculation but different result"

I mean... there is a reason, why Python's `unittest` module offers a [`assertAlmostEqual()`](https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertAlmostEqual) method ;-) (not that I say you should use that here, though unittest-style tests are [indeed possible](https://github.com/RIOT-OS/RIOT/blob/master/dist/pythonlibs/testrunner/unittest.py)).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16901#discussion_r717922018
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210928/7a4e156f/attachment.htm>


More information about the notifications mailing list