module TestExamples2DMHD

using Test
using Trixi

include("test_trixi.jl")

# pathof(Trixi) returns /path/to/Trixi/src/Trixi.jl, dirname gives the parent directory
EXAMPLES_DIR = joinpath(pathof(Trixi) |> dirname |> dirname, "examples", "2d")

@testset "MHD" begin
  @testset "elixir_mhd_alfven_wave.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_alfven_wave.jl"),
      l2   = [0.000112085405989522, 5.908049046758828e-6, 5.908049046772597e-6, 8.493815951190774e-6, 1.297306491315482e-6, 1.2316941466595997e-6, 1.2316941466702522e-6, 1.8368487700950752e-6, 4.4903164608485606e-7],
      linf = [0.0002693844074639351, 1.6289386154083596e-5, 1.6289386155082797e-5, 2.747802438275715e-5, 5.344948833307939e-6, 8.137608476288527e-6, 8.137608476843639e-6, 1.2121292898431557e-5, 2.306551665486275e-6])
  end

  @testset "elixir_mhd_alfven_wave_mortar.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_alfven_wave_mortar.jl"),
      l2   = [3.843336695097301e-6, 1.465357374916213e-6, 1.416088654606427e-6, 1.6806652628357514e-6, 1.4256305721007091e-6, 1.4507398918063128e-6, 1.397023085105777e-6, 1.704347968034822e-6, 8.210831113360175e-7],
      linf = [3.4691159990107856e-5, 1.4347253854782305e-5, 1.39581811973849e-5, 1.4252304932890758e-5, 8.244903569987194e-6, 1.0371383968976744e-5, 1.1133207181823757e-5, 1.600372637142189e-5, 5.572707635298199e-6],
      tspan = (0.0, 1.0))
  end

  @testset "elixir_mhd_ec.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_ec.jl"),
      l2   = [0.03628262478842946, 0.043011555956537974, 0.042997357872762064, 0.02574553086994775, 0.1620610267679157, 0.01745438427233919, 0.017455233781000938, 0.026879482381500206, 0.00020380087569640704],
      linf = [0.2351786266785303, 0.3156206778985494, 0.30941696929809714, 0.21167563519254826, 0.9688251298546073, 0.09076254289154928, 0.0916058976949814, 0.15698032974768517, 0.006131914796905391])
  end

  @testset "elixir_mhd_orszag_tang.jl" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_orszag_tang.jl"),
      l2   = [0.21671818699492046, 0.26364533451882755, 0.31388339884931576, 0.0, 0.5122729051056656, 0.2291828683723837, 0.34308184804821307, 0.0, 0.003210081660131638],
      linf = [1.2648775120640154, 0.673836824735164, 0.8585376516993447, 0.0, 2.8148181376188246, 0.657323372510843, 0.9595541188847632, 0.0, 0.0525390951527749],
      tspan = (0.0, 0.09))
  end

  @testset "elixir_mhd_orszag_tang.jl with flux_hll" begin
    @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_mhd_orszag_tang.jl"),
      l2   = [0.10793703703273708, 0.20177434827232335, 0.2296817363329907, 0.0, 0.2994119440979309, 0.15675567943351448, 0.24281245338083307, 0.0, 0.003548624701792127],
      linf = [0.560160833798496, 0.5098933680011135, 0.6566913038761877, 0.0, 0.9905839416293134, 0.39936698379939284, 0.6734754381366532, 0.0, 0.12739518123975463],
      tspan = (0.0, 0.06), surface_flux = flux_hll)
  end
end

end # module
