0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python to RubyAdvent Calendar 2021

Day 1

[py2rb] assertAlmostEqual

Last updated at Posted at 2022-01-04

はじめに

移植やってます。

assertAlmostEqual (Python)

概要が完成しましたので、テストを開始しています。

assertAlmostEqual

assertNotAlmostEqual(first, second, places=7, msg=None, delta=None)
first と second が近似的に等しい (等しくない) ことをテストします。これは、places (デフォルト7) で指定した小数位で丸めた差分をゼロと比較することで行われます

えっ、等しい場合はどうするのだろう。

[追記]

メソッド 確認事項
assertAlmostEqual(a, b) round(a-b, 7) == 0

assert (Ruby)

assert a.round(7) == b.round(7)

assert a != b && a.round(7) == b.round(7)

丸めた数値のみの比較ですとassertions
a != bをいれるとfailuresになるけど、前者にしましょう。

[追記]
前者が正しいです。ニホンゴムズカシイネ。
むしろ、確認事項にそって書けば

assert (a - b).round(7).zero?

メモ

  • Python の assertAlmostEqual を学習した
  • 百里を行く者は九十里を半ばとす
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?