|
| 1 | +defmodule InterpolationApp.CLI.ConfigParserTest do |
| 2 | + @moduledoc """ |
| 3 | + Testing InterpolationApp.CLI.ConfigParser |
| 4 | + """ |
| 5 | + |
| 6 | + use ExUnit.Case, async: true |
| 7 | + use Quixir |
| 8 | + |
| 9 | + alias InterpolationApp.CLI.ConfigParser |
| 10 | + |
| 11 | + describe "parse_args/1" do |
| 12 | + test "parses correct args" do |
| 13 | + args = ["methods=linear,lagrange3", "step=0.5", "accuracy=3"] |
| 14 | + |
| 15 | + assert ConfigParser.parse_args(args) == |
| 16 | + {:ok, |
| 17 | + %{ |
| 18 | + methods: [ |
| 19 | + InterpolationApp.Algo.LinearInterpolation, |
| 20 | + InterpolationApp.Algo.Lagrange3Interpolation |
| 21 | + ], |
| 22 | + step: 0.5, |
| 23 | + accuracy: 3 |
| 24 | + }} |
| 25 | + end |
| 26 | + |
| 27 | + test "returns error for no args" do |
| 28 | + assert match?({:error, _}, ConfigParser.parse_args([""])) |
| 29 | + end |
| 30 | + |
| 31 | + test "returns error for repetitive methods" do |
| 32 | + args = ["methods=linear,linear,linear", "step=0.5", "accuracy=3"] |
| 33 | + assert match?({:error, _}, ConfigParser.parse_args(args)) |
| 34 | + end |
| 35 | + |
| 36 | + test "returns error for invalid methods" do |
| 37 | + args = ["methods=invalid,method", "step=0.5", "accuracy=3"] |
| 38 | + assert match?({:error, _}, ConfigParser.parse_args(args)) |
| 39 | + end |
| 40 | + |
| 41 | + test "returns error for invalid step" do |
| 42 | + args = ["methods=invalid,method", "step=-0.5", "accuracy=3"] |
| 43 | + assert match?({:error, _}, ConfigParser.parse_args(args)) |
| 44 | + end |
| 45 | + |
| 46 | + test "returns error for invalid accuracy" do |
| 47 | + args = ["methods=invalid,method", "step=-0.5", "accuracy=3.2"] |
| 48 | + assert match?({:error, _}, ConfigParser.parse_args(args)) |
| 49 | + end |
| 50 | + |
| 51 | + test "accepts positive float step and integer accuracy" do |
| 52 | + ptest step: float(min: 0.1), accuracy: int(min: 1) do |
| 53 | + args = ["methods=linear", "step=#{step}", "accuracy=#{accuracy}"] |
| 54 | + {:ok, config} = ConfigParser.parse_args(args) |
| 55 | + config.step == step and config.accuracy == accuracy |
| 56 | + end |
| 57 | + end |
| 58 | + end |
| 59 | +end |
0 commit comments