始める無料で始める

Convert an example into a test

Unit tests are crucial for verifying the behavior of individual components in the unitConverter package. They help catch bugs and errors early, providing a safety net during code modification. Additionally, unit tests facilitate collaboration among developers and maintain code quality.

In this exercise, you will be given a code example from the unitConverter package. Converting examples into unit tests is a common first step in creating them. Successfully defining the expectation function is an important piece in unit test creation.

The testthat package and the unitConverter package at this point in development have been loaded for you.

この演習はコースの一部です

Developing R Packages

コースを見る

演習の手順

  • Review the dist_converter() example.
  • Turn the given example into a unit test checking for similarity.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Review the example
dist_converter(100, unit_from = "meters", unit_to = "feet")

# Convert the example to a unit test comparing sameness
___
コードを編集して実行