defmodule Mix.Tasks.ExampleTest do use Mix.Task import Sparklinex @output_dir "test/actual" @test_data [ 1, 5, 15, 20, 30, 50, 57, 58, 55, 48, 44, 43, 42, 42, 46, 48, 49, 53, 55, 59, 60, 65, 75, 90, 105, 106, 107, 110, 115, 120, 115, 120, 130, 140, 150, 160, 170, 100, 100, 10 ] def run(_) do File.mkdir_p(@output_dir) basic_graphs = [:smooth] basic_graphs |> Enum.each( fn graph_type -> quick_graph("#{graph_type}", %{type: graph_type}) quick_graph("labeled_#{graph_type}", %{type: graph_type, label: "Glucose"}) end ) write_html() end def quick_graph(name, options) do @test_data |> graph(options) |> graph_to_file("#{@output_dir}/#{name}.png") end defp write_html do {:ok, file} = File.open "test/actual/index.html", [:write] IO.binwrite(file, html_header()) IO.binwrite(file, table_header()) Path.wildcard("test/expected/*") |> Enum.each(fn test_file -> IO.binwrite(file, table_row(test_file)) end) IO.binwrite(file, close()) File.close(file) end defp table_row(file) do """
| Expected | Actual |