text:
using Test
using ChemistryFeaturization
using SimpleWeightedGraphs

include("../src/layers.jl")
using .Layers: AGNConv, AGNPool

@testset "AGNConv" begin
    # create simple line graph, populate it with feature of all ones
    adjmat = Float64.([0 1 0; 1 0 1; 0 1 0])
    ag = AtomGraph(adjmat, ["C", "C", "C"])
    dummyfzn = GraphNodeFeaturization(["Block"])
    fa = featurize(ag, dummyfzn)

    # create a conv layer, initialize weights with ones
    l = AGNConv(4 => 4, initW = ones)

    # test output looks as expected
    output_fea = l(fa)[2]
    @test output_fea[:, 1] == output_fea[:, 3]
    @test isapprox(output_fea[:, 1] .+ output_fea[:, 3], .-output_fea[:, 2])

    # and now for a loop
    adjmat = Float64.([0 1 1; 1 0 1; 1 1 0])
    ag = Atoms.AtomGraph(adjmat, ["C", "C", "C"])
    fa = featurize(ag, dummyfzn)
    @test all(isapprox.(l(fa)[2], zero(Float64), atol = 1e-12))
end

@testset "pooling" begin
    # keep our little line graph, but give it more features
    adjmat = Float64.([0 1 0; 1 0 1; 0 1 0])
    feat = ones(Float64, 50, 3)

    # make some pooling layers
    meanpool = AGNPool("mean", 50, 10, 0.1)
    maxpool = AGNPool("max", 50, 10, 0.1)

    # start with the easy stuff
    # (also actually test that it evaluates on the FeaturizedAtoms too)
    @test meanpool(feat) == ones(Float64, 10, 1)
    @test maxpool(feat) == ones(Float64, 10, 1)

    # one level up
    feat[:, 2] .= 0.0
    # they're still the same here because maxpool takes max along features but averages across nodes right now
    @test all(isapprox.(meanpool(feat), 2 / 3))
    @test all(isapprox.(maxpool(feat), 2 / 3))

    # and now make them different
    feat[1:5:50, 2] .= 4.0
    @test all(isapprox.(meanpool(feat), 14 / 15))
    @test all(maxpool(feat) .== 2.0)

    # make sure it complains when it should
    @test_throws AssertionError AGNPool("mean", 10, 20, 0.5)
end

ext: jl


text:
# Seed
Random.seed!(42) # in case solvers use stochastic algorithms

# Setup
StoppingProblem = @with_kw (μ_bar = -0.01,
                          σ_bar = 0.01,
                          S_bar = 10.0,
                          γ = 0.5, # u(x) = x^γ
                          ρ = 0.05, # discount rate
                          x_min = 0.01,
                          x_max = 5.0,
                          M = 15) # num of grid points

function LCP_objects(sp)
# setup
  @unpack μ_bar, σ_bar, S_bar, γ, ρ, x_min, x_max, M = sp
  grid = range(x_min, x_max, length = M)
  grid_extended = [grid[1] - diff(grid)[1]; grid; grid[end] + diff(grid)[end]]
  μ = μ_bar
  S(x) = S_bar
  u(x) = x^γ
  σ = σ_bar
# construct operator
  L = μ * L₁₋bc(grid_extended, (Reflecting(), Reflecting())) + σ^2/2 * L₂bc(grid_extended, (Reflecting(), Reflecting()))
# construct/return LCP objects
  B = ρ*I - L
  S_vec = S.(grid)
  q_vec = -u.(grid) + B*S_vec
  return (L = L, B = B, S = S_vec, q = q_vec)
end

function LCPsolve(sp)
  @unpack L, B, S, q = LCP_objects(sp)
  f = z -> B*z + q
  n = sp.M
  lb = zeros(n)
  ub = 300*ones(n) # a reasonable guess?
  options(convergence_tolerance = 1e-12, output = :no, time_limit = 600) # 10 minute budget
  exit_code, sol_z, sol_f = @suppress solveLCP(f, lb, ub);
end

@testset "Backward Case, Nonzero S" begin
  code, sol, f = LCPsolve(StoppingProblem())
  @test code == :Solved
  @test sol[1] ≈ 0.0 atol = 1e-5
  @test sol[5] ≈ 12.066957816758809 atol = 1e-5
  @test f[1] ≈ 0.39946441597137766 atol = 1e-5
end

@testset "Backward Case, Zero S" begin
  code, sol, f = LCPsolve(StoppingProblem(S_bar = 0.))
  @test code == :Solved
  @test sol[1] ≈ 2.050665004133949 atol = 1e-5
  @test sol[8] ≈ 30.258918534086924 atol = 1e-5
  @test f[1] ≈ 0.0 atol = 1e-5
end

function LCP_split(S)
  # setup
    u(x) = x^2
    ρ = 0.75
    μ(x) = -x
    σ = 0.1
    M = 300
    x = range(-5., 5., length = M)
    x̄ = [x[1] - diff(x)[1]; x; x[end] + diff(x)[end]]
    bc = (Reflecting(), Reflecting())
    L₁ = Diagonal(min.(μ.(x), 0.0)) * L₁₋bc(x̄, bc) + Diagonal(max.(μ.(x), 0.0)) * L₁₊bc(x̄, bc)
  # operator construction
    L = L₁+ σ^2/2 * L₂bc(x̄, bc)
  # LCP stuff
    B = ρ*I - L
    S_vec = S * ones(M)
    q_vec = -u.(x) + B*S_vec
    return (L = L, B = B, S = S_vec, q = q_vec)
end

@testset "Split Case, Nonzero S" begin
  # setup
  @unpack L, B, S, q = LCP_split(0.125)
  f = z -> B*z + q
  n = 300
  lb = zeros(n)
  ub = 300*ones(n) # a reasonable guess?
  options(convergence_tolerance = 1e-12, output = :no, time_limit = 600) # 10 minute budget
  exit_code, sol_z, sol_f = @suppress solveLCP(f, lb, ub);

  # tests
  @test exit_code == :StationaryPointFound
  @test sol_z[3] ≈ 8.774937148286833 atol = 1e-5
  @test sol_z[120] ≈ 0.3021168981772892 atol = 1e-5
  @test sol_z[270] ≈ 5.729541001488482 atol = 1e-5
  @test sol_f[end-1] ≈ 3.197442310920451e-14 atol = 1e-5
end

@testset "Split Case, Zero S" begin
  # setup
  @unpack L, B, S, q = LCP_split(0.)
  f = z -> B*z + q
  n = 300
  lb = zeros(n)
  ub = 300*ones(n) # a reasonable guess?
  options(convergence_tolerance = 1e-12, output = :no, time_limit = 600) # 10 minute budget
  exit_code, sol_z, sol_f = @suppress solveLCP(f, lb, ub);

  # tests
  @test exit_code == :StationaryPointFound
  @test sol_z[3] ≈ 8.888461348456772 atol = 1e-5
  @test sol_z[76] ≈ 2.279767804635279 atol = 1e-5
  @test sol_z[150] ≈ 0.005770703117189083 atol = 1e-5
  @test sol_z[269] ≈ 5.744079221450249 atol = 1e-5
  @test sol_f[123] ≈ 1.7763568394002505e-15 atol = 1e-5
end


text:
using Test
using OpenQuantumSystems
using Random, SparseArrays, LinearAlgebra, StableRNGs

@testset "trace" begin

    Random.seed!(StableRNG(0), 1)

    D(op1::Array, op2::Array) = abs(norm(op1 - op2))
    D(x1::StateVector, x2::StateVector) = norm(x2 - x1)
    D(op1::AbstractOperator, op2::AbstractOperator) =
        abs(tracedistance_nh(dense(op1), dense(op2)))
    D(op1::AbstractSuperOperator, op2::AbstractSuperOperator) =
        abs(tracedistance_nh(dense(op1), dense(op2)))

    # TODO: change to macro
    mode1 = Mode(0.2, 1.0)
    Energy = [0.0, 200.0]
    mol1 = Molecule([mode1], 3, Energy)
    mol2 = Molecule([mode1], 3, Energy)
    agg = Aggregate([mol1, mol2])
    aggInds = getIndices(agg)
    vibindices = getVibIndices(agg, aggInds)
    aggIndsLen = length(aggInds)
    basis = GenericBasis([aggIndsLen])
    FCFact = getFranckCondonFactors(agg, aggInds)

    Ham = getAggHamiltonian(agg, aggInds, FCFact)
    Ham_I = getAggHamInteraction(agg, aggInds, FCFact)
    Ham_0 = getAggHamSystemBath(agg, aggInds, FCFact)

    data = Matrix(Hermitian(rand(StableRNG(0), ComplexF64, aggIndsLen, aggIndsLen)))
    rho0 = DenseOperator(basis, basis, data)
    normalize!(rho0)

    t = 0.0
    U_op = evolutionOperator(Ham, t)
    rho = U_op * rho0 * U_op'
    rho_traced_ref = ComplexF64[0.30545089951602383 + 0.0im 0.14375197756961597 + 0.21658981002618588im 0.23626964940425038 + 0.1914303091850988im; 0.14375197756961597 - 0.21658981002618588im 0.30379617012935617 + 1.5178830414797062e-18im 0.15887255193342634 + 0.11195793936579877im; 0.23626964940425035 - 0.19143030918509882im 0.15887255193342636 - 0.11195793936579874im 0.4026345547478164 - 1.734723475976807e-18im]
    rho_traced = trace_bath_slow(rho, agg, FCFact, aggInds, vibindices)
    @test 1e-7 > D(rho_traced.data, rho_traced_ref)
    rho_traced =
        trace_bath_slow(rho.data, agg, FCFact, aggInds, vibindices)
    @test 1e-7 > D(rho_traced, rho_traced_ref)

    FCProd = getFCProd(agg, FCFact, aggInds, vibindices)
    rho_traced = trace_bath(rho, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho_traced.data, rho_traced_ref)
    rho_traced = trace_bath(rho.data, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho_traced, rho_traced_ref)

    for a = 1:3, b = 1:3
        rho_traced_ab = trace_bath(rho, a, b, agg, FCProd, aggInds, vibindices)
        @test 1e-7 > abs(rho_traced_ref[a, b] - rho_traced_ab)
    end

    rho_bath = get_rho_bath(rho0, agg, FCProd, aggInds, vibindices)
    rho_traced = trace_bath(rho_bath, agg, FCProd, aggInds, vibindices)
    rho_traced_ref = [1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0]
    @test 1e-10 > D(rho_traced_ref, rho_traced.data)

    rho_traced = trace_bath(rho0, agg, FCProd, aggInds, vibindices)
    rho0_ad = ad(rho_traced, rho_bath, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho0, rho0_ad)

    t = 1.0
    U_op = evolutionOperator(Ham, t)
    rho = U_op * rho0 * U_op'
    rho_traced_ref = ComplexF64[0.30545089951602605 + 3.0357660829594124e-18im 0.19173860810181675 - 0.0844643501820273im 0.19018921460047641 - 0.20310674141599672im; 0.19173860810181684 + 0.0844643501820273im 0.3499470437099394 + 8.50622960880644e-18im 0.13057918573136992 + 0.08614578235028769im; 0.19018921460047636 + 0.20310674141599672im 0.13057918573136984 - 0.08614578235028776im 0.411399271707198 + 6.1416735243015536e-18im]
    rho_traced = trace_bath_slow(rho, agg, FCFact, aggInds, vibindices)
    @test 1e-7 > D(rho_traced.data, rho_traced_ref)
    rho_traced =
        trace_bath_slow(rho.data, agg, FCFact, aggInds, vibindices)
    @test 1e-7 > D(rho_traced, rho_traced_ref)

    FCProd = getFCProd(agg, FCFact, aggInds, vibindices)
    rho_traced = trace_bath(rho, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho_traced.data, rho_traced_ref)
    rho_traced = trace_bath(rho.data, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho_traced, rho_traced_ref)

    for a = 1:3, b = 1:3
        rho_traced_ab = trace_bath(rho, a, b, agg, FCProd, aggInds, vibindices)
        @test 1e-7 > abs(rho_traced_ref[a, b] - rho_traced_ab)

        rho_ab = take_el_part(rho.data, a, b, vibindices)
        rho_traced_ab = trace_bath_part(
            rho_ab,
            a,
            b,
            agg,
            FCProd,
            aggInds,
            vibindices
        )
        @test 1e-7 > abs(rho_traced_ref[a, b] - rho_traced_ab)
    end

    rho_bath = get_rho_bath(rho0, agg, FCProd, aggInds, vibindices)
    rho_traced = trace_bath(rho_bath, agg, FCProd, aggInds, vibindices)
    rho_traced_ref = [1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0]
    @test 1e-10 > D(rho_traced_ref, rho_traced.data)

    rho_traced = trace_bath(rho0, agg, FCProd, aggInds, vibindices)
    rho0_ad = ad(rho_traced, rho_bath, agg, FCProd, aggInds, vibindices)
    @test 1e-7 > D(rho0, rho0_ad)

    rho_bath = get_rho_bath(rho0, agg, FCProd, aggInds, vibindices)

    t = 0.0
    Ham_II_t = getInteractionHamIPicture(Ham_0, Ham_I, t)
    prod = Ham_II_t * Ham_I * rho_bath
    corr_ref = trace_bath(prod, agg, FCProd, aggInds, vibindices)
    corr = correlation_function(
        t,
        rho_bath,
        Ham_0,
        Ham_I,
        agg,
        FCProd,
        aggInds,
        vibindices
    )
    @test 1e-7 > D(corr, corr_ref)

    t = 1.0
    Ham_II_t = getInteractionHamIPicture(Ham_0, Ham_I, t)
    prod = Ham_II_t * Ham_I * rho_bath
    corr_ref = trace_bath(prod, agg, FCProd, aggInds, vibindices)
    corr = correlation_function(
        t,
        rho_bath,
        Ham_0,
        Ham_I,
        agg,
        FCProd,
        aggInds,
        vibindices
    )
    @test 1e-7 > D(corr, corr_ref)

end


text:
is_response(elem::HTMLElement) = any(is_response, elem.children)
is_response(elem::HTMLText) = occursin(r"^[A-E]\.", elem.text)

struct Response
    content
    label
    id
    correct
end

function Base.occursin(pat, r::Response)
    for node in PreOrderDFS(r.content)
        if node isa HTMLText
            occursin(pat, node.text) && return true
        end
    end
    return false
end

function Base.replace!(r::Response, rep::Pair)
    for node in PreOrderDFS(r.content)
        if node isa HTMLText
            node.text = replace(node.text, rep)
        end
    end
    return r
end

_isempty(x::HTMLText) = isempty(x.text)
_isempty(x::HTMLElement) = isempty(x.children) || all(_isempty(child) for child in x.children)

function cleanup_strong!(elem::HTMLElement)
    if length(elem.children) == 1 && first(elem.children) isa HTMLElement{:strong}
        elem.children = [elem.children[1].children[1]]
    else
        filter!(x -> !(isa(x, HTMLElement{:strong}) && _isempty(x)), elem.children)
    end
    return elem
end

cleanup_strong!(elem::HTMLText) = HTMLText

function response(elem::HTMLElement, label, correct=false)
    elem = deepcopy(elem)
    for node in PostOrderDFS(elem)
        if node isa HTMLText
            node.text = replace(node.text, r"[A-E]+\. ?" => "")
        end
    end

    # re-parse to get rid of any emtpy elements.  children[2] is <body>, children[1] is body contents
    elem = cleanup_strong!(parsehtml(string(elem)).root.children[2].children[1])
    Response(elem, label, string(uuid4()), correct)
end

Base.show(io::IO, r::Response) =
    print(
        io,
        r.correct ? "✔ " : "✘ ",
        r.label, ". ",
        r.content
    )


text:
"""
    struct EpsilonGreedyPolicy <: AbstractPolicy
        table::Vector{Int}
        nactions::Int
        ϵ::Float64
    end

Just like the [`DeterministicPolicy`](@ref), the best actions are stored in the `table`.
However the best action will only be taken at a portion of 1 - ϵ.

See also: [`EpsilonGreedySelector`](@ref)
"""
struct EpsilonGreedyPolicy <: AbstractPolicy
    table::Vector{Int}
    nactions::Int
    ϵ::Float64
end

function (p::EpsilonGreedyPolicy)(s::Int)
    if rand() > p.ϵ
        p.table[s]
    else
        rand(1:p.nactions)
    end
end

function (p::EpsilonGreedyPolicy)(s::Int, ::Val{:dist})
    prob = fill(p.ϵ/p.nactions, p.nactions)
    prob[p.table[s]] += 1 - p.ϵ
    prob
end

(p::EpsilonGreedyPolicy)(s::Int, a::Int) = p.table[s] == a ? (1 - p.ϵ) + p.ϵ / p.nactions : p.ϵ / p.nactions

update!(p::EpsilonGreedyPolicy, s::Int, a::Int) = p.table[s] = a


text:
# -*- encoding: utf-8 -*-
#
# The MIT License (MIT)
#
# Copyright © 2021 Matteo Foglieni and Riccardo Gervasoni
#

@testset "test_check_is_positive" begin
     @test Raytracing.check_is_positive("")
     @test Raytracing.check_is_positive("    ")
     @test Raytracing.check_is_positive(" 3 ")
     @test Raytracing.check_is_positive(" 0.0 ")
     @test Raytracing.check_is_positive("3.0 ")
     @test !Raytracing.check_is_positive("-3.4")
     @test !Raytracing.check_is_positive(" -3")
end

@testset "test_string2positive" begin
     @test Raytracing.string2positive("") == 0.0
     @test Raytracing.string2positive("    ") == 0.0
     @test Raytracing.string2positive(" 3 ") == 3.0
     @test Raytracing.string2positive(" 0.0 ") == 0.0
     @test Raytracing.string2positive("3.0 ") == 3.0
     @test_throws ArgumentError Raytracing.string2positive("-3.4")
     @test_throws ArgumentError Raytracing.string2positive("-3")
end

##########################################################################################92

@testset "test_check_is_uint64" begin
     @test Raytracing.check_is_uint64("")
     @test Raytracing.check_is_uint64("    ")
     @test Raytracing.check_is_uint64(" 3 ")
     @test Raytracing.check_is_uint64("3.0 ")
     @test !Raytracing.check_is_uint64("3.4")
     @test !Raytracing.check_is_uint64("-3")
end

@testset "test_string2int64" begin
     @test Raytracing.string2int64("") == 0
     @test Raytracing.string2int64("", true) == UInt64(0)
     @test Raytracing.string2int64("", false) == 0
     @test Raytracing.string2int64("    ") == 0
     @test Raytracing.string2int64("    ", true) == UInt64(0)
     @test Raytracing.string2int64("    ", false) == 0
     @test Raytracing.string2int64(" 3 ") == 3
     @test Raytracing.string2int64(" 3 ", true) == UInt64(3)
     @test Raytracing.string2int64(" 3 ", false) == 3
     @test Raytracing.string2int64("3.0 ") == 3
     @test Raytracing.string2int64("3.0 ", true) == UInt64(3)
     @test Raytracing.string2int64("3.0 ", false) == 3
     @test_throws ArgumentError Raytracing.string2int64("3.4")
     @test_throws ArgumentError Raytracing.string2int64("-3")
     @test_throws ArgumentError Raytracing.string2int64("3.4", true)
     @test_throws ArgumentError Raytracing.string2int64("-3", true)
     @test_throws ArgumentError Raytracing.string2int64("3.4", false)
     @test_throws ArgumentError Raytracing.string2int64("-3", false)
end

##########################################################################################92

@testset "test_check_is_even_uint64" begin
     @test Raytracing.check_is_even_uint64("")
     @test Raytracing.check_is_even_uint64("    ")
     @test Raytracing.check_is_even_uint64(" 0 ")
     @test Raytracing.check_is_even_uint64("0.0 ")
     @test Raytracing.check_is_even_uint64(" 2 ")
     @test Raytracing.check_is_even_uint64("2.0 ")
     @test Raytracing.check_is_even_uint64(" 4 ")
     @test Raytracing.check_is_even_uint64("4.0 ")
     @test !Raytracing.check_is_even_uint64("2.5")
     @test !Raytracing.check_is_even_uint64("1")
     @test !Raytracing.check_is_even_uint64("3")
     @test !Raytracing.check_is_even_uint64("-4")
end

@testset "test_string2evenint64" begin
     @test Raytracing.string2evenint64("") == 0
     @test Raytracing.string2evenint64("", true) == UInt64(0)
     @test Raytracing.string2evenint64("", false) == 0
     @test Raytracing.string2evenint64("    ") == 0
     @test Raytracing.string2evenint64("    ", true) == UInt64(0)
     @test Raytracing.string2evenint64("    ", false) == 0
     @test Raytracing.string2evenint64(" 2 ") == 2
     @test Raytracing.string2evenint64(" 2 ", true) == UInt64(2)
     @test Raytracing.string2evenint64(" 2 ", false) == 2
     @test Raytracing.string2evenint64("2.0 ") == 2
     @test Raytracing.string2evenint64("  2.0 ", true) == UInt64(2)
     @test Raytracing.string2evenint64("2.0 ", false) == 2
     @test_throws ArgumentError Raytracing.string2evenint64("3.4")
     @test_throws ArgumentError Raytracing.string2evenint64("-3")
     @test_throws ArgumentError Raytracing.string2evenint64("3", true)
     @test_throws ArgumentError Raytracing.string2evenint64("3.4", true)
     @test_throws ArgumentError Raytracing.string2evenint64("-3", true)
     @test_throws ArgumentError Raytracing.string2evenint64("3.4", false)
     @test_throws ArgumentError Raytracing.string2evenint64("-3", false)
end

##########################################################################################92

@testset "test_check_is_square" begin
     @test Raytracing.check_is_square("")
     @test Raytracing.check_is_square("    ")
     @test Raytracing.check_is_square(" 0 ")
     @test Raytracing.check_is_square(" 1 ")
     @test Raytracing.check_is_square(" 4 ")
     @test Raytracing.check_is_square(" 4.0 ")
     @test Raytracing.check_is_square(" 9 ")
     @test Raytracing.check_is_square(" 9.0 ")
     @test !Raytracing.check_is_square("3")
     @test !Raytracing.check_is_square("-4")
     @test !Raytracing.check_is_square("10.0")
end

@testset "test_string2rootint64" begin
     @test Raytracing.string2rootint64("") == 0
     @test Raytracing.string2rootint64("    ") == 0
     @test Raytracing.string2rootint64(" 0 ") == 0
     @test Raytracing.string2rootint64(" 1 ") == 1
     @test Raytracing.string2rootint64(" 4 ") == 2
     @test Raytracing.string2rootint64(" 4.0 ") == 2
     @test Raytracing.string2rootint64(" 9 ") == 3
     @test Raytracing.string2rootint64(" 9.0 ") == 3
     @test_throws ArgumentError Raytracing.string2rootint64("3")
     @test_throws ArgumentError Raytracing.string2rootint64("-4")
     @test_throws ArgumentError Raytracing.string2rootint64("10.0")
end

##########################################################################################92

@testset "test_check_is_color" begin
     @test Raytracing.check_is_color("")
     @test Raytracing.check_is_color("  ")
     @test Raytracing.check_is_color("<0,0,0>")
     @test Raytracing.check_is_color("<1.0,  2, pi >   ")
     @test !Raytracing.check_is_color("3")
     @test !Raytracing.check_is_color("0,0,0")
     @test !Raytracing.check_is_color("[0,0,0]")
     @test !Raytracing.check_is_color("<0 0 0>")
end

@testset "test_string2color" begin
     @test Raytracing.string2color("") == RGB{Float32}(0,0,0)
     @test Raytracing.string2color("  ") == RGB{Float32}(0,0,0)
     @test Raytracing.string2color("<0,0,0>") == RGB{Float32}(0,0,0)
     @test Raytracing.string2color("<1.0,  2, pi >   ") == RGB{Float32}(1,2,π)
     @test_throws ArgumentError Raytracing.string2color("3")
     @test_throws ArgumentError Raytracing.string2color("0,0,0")
     @test_throws ArgumentError Raytracing.string2color("[0,0,0]")
     @test_throws ArgumentError Raytracing.string2color("<0 0 0>")
end

##########################################################################################92

@testset "test_check_is_vector" begin
     @test Raytracing.check_is_vector("")
     @test Raytracing.check_is_vector("  ")
     @test Raytracing.check_is_vector("[0,0,0]")
     @test Raytracing.check_is_vector("[1.0,  2, pi]   ")
     @test !Raytracing.check_is_vector("3")
     @test !Raytracing.check_is_vector("0,0,0")
     @test !Raytracing.check_is_vector("<0,0,0>")
     @test !Raytracing.check_is_vector("[0 0 0]")
end

@testset "test_string2vector" begin
     @test Raytracing.string2vector("") == Raytracing.Vec(0.,0.,0.)
     @test Raytracing.string2vector("  ") == Raytracing.Vec(0.,0.,0.)
     @test Raytracing.string2vector("[0,0,0]") == Raytracing.Vec(0.,0.,0.)
     @test Raytracing.string2vector("[1.0,  2, pi ]   ") == Raytracing.Vec(1.,2.,π)
     @test_throws ArgumentError Raytracing.string2vector("3")
     @test_throws ArgumentError Raytracing.string2vector("0,0,0")
     @test_throws ArgumentError Raytracing.string2vector("<0,0,0>")
     @test_throws ArgumentError Raytracing.string2vector("[0 0 0]")
end

##########################################################################################92

@testset "test_check_is_declare_float" begin
     @test Raytracing.check_is_declare_float("")
     @test Raytracing.check_is_declare_float("  ")
     @test Raytracing.check_is_declare_float("nome1:1.01,nome2:3.14")
     @test Raytracing.check_is_declare_float(" nome:    1.09013")
     @test Raytracing.check_is_declare_float("var1 : 1, var2 : 2 , var3:5.64")
     @test !Raytracing.check_is_declare_float("prova , 1")
     @test !Raytracing.check_is_declare_float(" prova : 1 ,")
     @test !Raytracing.check_is_declare_float("prova")
end

@testset "test_declare_float2dict" begin
     @test isnothing(Raytracing.declare_float2dict(""))
     @test isnothing(Raytracing.declare_float2dict("  "))
     @test Raytracing.declare_float2dict("nome1:1.01,nome2:3.14") == Dict("nome1" => 1.01, "nome2" =>3.14)
     @test Raytracing.declare_float2dict(" nome:    1.09013") == Dict("nome" =>  1.09013)
     @test Raytracing.declare_float2dict("var1 : 1, var2 : 2 , var3:5.64")  == Dict("var1" => 1, "var2" =>2, "var3"=>5.64)
     @test_throws ArgumentError Raytracing.declare_float2dict("prova , 1")
     @test_throws ArgumentError Raytracing.declare_float2dict(" prova : 1 ,")
     @test_throws ArgumentError Raytracing.declare_float2dict("prova")
end

##########################################################################################92

@testset "test_check_is_one_of" begin
     @test Raytracing.check_is_one_of("per", CAMERAS)
     @test Raytracing.check_is_one_of("ort", CAMERAS)
     @test Raytracing.check_is_one_of("  per    ", CAMERAS)
     @test Raytracing.check_is_one_of("ort   ", CAMERAS)
     @test !Raytracing.check_is_one_of("", CAMERAS)
     @test !Raytracing.check_is_one_of("  ", CAMERAS)
     @test !Raytracing.check_is_one_of("prova", CAMERAS)
end

@testset "test_string2stringoneof" begin
     @test Raytracing.string2stringoneof("per", CAMERAS) == "per"
     @test Raytracing.string2stringoneof("ort", CAMERAS) == "ort"
     @test Raytracing.string2stringoneof("per   ", CAMERAS) == "per"
     @test Raytracing.string2stringoneof("  ort ", CAMERAS) == "ort"
     @test_throws ArgumentError Raytracing.string2stringoneof("", CAMERAS)
     @test_throws ArgumentError Raytracing.string2stringoneof("   ", CAMERAS)
     @test_throws ArgumentError Raytracing.string2stringoneof("prova ", CAMERAS)
end

##########################################################################################92

@testset "test_check_is_iterable_1" begin
     @test Raytracing.check_is_iterable(1)
     @test Raytracing.check_is_iterable(1:5)
     @test Raytracing.check_is_iterable([0.1 , 2, 14])

     @test Raytracing.check_is_iterable(1, Int64)
     @test Raytracing.check_is_iterable(1, Number)
     @test Raytracing.check_is_iterable(1:5, Int64)
     @test Raytracing.check_is_iterable(1:5, Number)
     @test Raytracing.check_is_iterable([0.1 , 2, 14], Float64)
     @test Raytracing.check_is_iterable([0.1 , 2, 14], Number)

     @test !Raytracing.check_is_iterable([0.1 , 2, 14], Int64)
end

@testset "test_check_is_iterable_2" begin
     @test Raytracing.check_is_iterable("1")
     @test Raytracing.check_is_iterable("1:5")
     @test Raytracing.check_is_iterable("[0.1 , 2, 14]")

     @test Raytracing.check_is_iterable("1", Int64)
     @test Raytracing.check_is_iterable("1", Number)
     @test Raytracing.check_is_iterable("1:5", Int64)
     @test Raytracing.check_is_iterable("1:5", Number)
     @test Raytracing.check_is_iterable("[0.1 , 2, 14]", Float64)
     @test Raytracing.check_is_iterable("[0.1 , 2, 14]", Number)

     @test !Raytracing.check_is_iterable("[0.1 , 2, 14]", Int64)
end

@testset "test_string2iterable" begin
     @test Raytracing.string2iterable("1.0") == 1
     @test Raytracing.string2iterable("1:5") == 1:5
     @test Raytracing.string2iterable("[0.1 , 2, 14]") == [0.1, 2, 14]

     @test Raytracing.string2iterable("1", Int64) == 1
     @test Raytracing.string2iterable("1", Number) == 1
     @test Raytracing.string2iterable("1:5", Int64) == 1:5
     @test Raytracing.string2iterable("1:5", Number) == 1:5
     @test Raytracing.string2iterable("[0.1 , 2, 14]", Float64) == [0.1, 2, 14]
     @test Raytracing.string2iterable("[0.1 , 2, 14]", Number) == [0.1, 2, 14]
end

##########################################################################################92

@testset "test_check_is_vec_variables" begin
     @test Raytracing.check_is_vec_variables("")
     @test Raytracing.check_is_vec_variables("  ")
     @test Raytracing.check_is_vec_variables("[nome1,nome2]")
     @test Raytracing.check_is_vec_variables("  [  nome  ]")
     @test Raytracing.check_is_vec_variables("[var1 ,  var2 , var3    ]")
     @test !Raytracing.check_is_vec_variables("prova , 1")
     @test !Raytracing.check_is_vec_variables("[ prova : 1 ]")
     @test !Raytracing.check_is_vec_variables("prova")
end

@testset "test_string2vec_variables" begin
     @test isnothing(Raytracing.string2vec_variables(""))
     @test isnothing(Raytracing.string2vec_variables("  "))
     @test Raytracing.string2vec_variables("[nome1,nome2]") == ["nome1", "nome2"]
     @test Raytracing.string2vec_variables("  [  nome  ]") == ["nome"]
     @test Raytracing.string2vec_variables("[var1 ,  var2 , var3    ]") == ["var1", "var2", "var3"]
     @test_throws ArgumentError Raytracing.string2vec_variables("prova , 1")
     @test_throws ArgumentError Raytracing.string2vec_variables("[ prova : 1 ]")
     @test_throws ArgumentError Raytracing.string2vec_variables("prova")
end

##########################################################################################92

@testset "test_check_is_function" begin
     @test !Raytracing.check_is_function("")
     @test !Raytracing.check_is_function("  ")
     @test !Raytracing.check_is_function("[nome1,nome2]")
     @test Raytracing.check_is_function("check_is_function")
     @test Raytracing.check_is_function("check_is_declare_float")
end

@testset "test_string2vec_variables" begin
     @test_throws ArgumentError Raytracing.string2function("")
     @test_throws ArgumentError Raytracing.string2function("  ")
     @test_throws ArgumentError Raytracing.string2function("[nome1,nome2]")
     @test Raytracing.string2function("check_is_declare_float") == check_is_declare_float
end

##########################################################################################92

@testset "test_from_CLI_to_vecstring" begin
     string="""./Raytracer.jl render --ONLY_FOR_TESTS pathtracer --background_color="<1,2,3>" """*
     """--init_state=1 --init_seq=2 --num_of_rays=15 --max_depth=3 --russian_roulette_limit 1"""
     vec_string = ["render", "--ONLY_FOR_TESTS", "pathtracer", "--background_color=<1,2,3>",
     "--init_state=1", "--init_seq=2", "--num_of_rays=15", "--max_depth=3", "--russian_roulette_limit", "1"]
     @test Raytracing.from_CLI_to_vecstring(string) == vec_string
end

string="""./Raytracer.jl render --ONLY_FOR_TESTS pathtracer --background_color="<1,2,3>" --init_state=1 --init_seq=2 --num_of_rays=15 --max_depth=3 --russian_roulette_limit 1"""


text:
using DelimitedFiles

function simulate!(X, mcProcess::BrownianMotion, mcBaseData::MonteCarloConfiguration{type1, type2, type3, SerialMode, type5}, T::numb) where {numb <: Number, type1 <: Number, type2 <: Number, type3 <: PrescribedMC, type5 <: Random.AbstractRNG}
    Nsim = mcBaseData.Nsim
    Nstep = mcBaseData.Nstep
    σ = mcProcess.σ
    μ = mcProcess.μ
    @assert T > 0
    dt = T / Nstep
    mean_bm = μ * dt
    stddev_bm = σ * sqrt(dt)
    isDualZero = mean_bm * stddev_bm * 0
    #X=Matrix{typeof(isDualZero)}(undef,Nsim,Nstep+1);
    Z = DelimitedFiles.readdlm("C:\\Users\\Nicola\\.julia\\dev\\FinancialMonteCarlo\\src\\models\\matrix.txt")[1:Nsim, 1:Nstep]
    view(X, :, 1) .= isDualZero
    @inbounds for i = 1:Nsim
        @inbounds for j = 1:Nstep
            x_i_j = @views X[i, j]
            z_i_j = @views Z[i, j]
            X[i, j+1] = x_i_j + mean_bm + stddev_bm * z_i_j
        end
    end

    return X
end


text:
function shuffle!(r::AbstractRNG, a::AbstractVector)
    for i = length(a):-1:2
        j = rand(r, 1:i)
        a[i], a[j] = a[j], a[i]
    end
    return a
end

max_stars_repo_name: ethansaxenian/RosettaDecode

max_issues_repo_name: ethansaxenian/RosettaDecode

max_forks_repo_name: ethansaxenian/RosettaDecode


text:
using Documenter, GradDescent

makedocs(modules=[GradDescent],
    sitename="GradDescent.jl",
    format = Documenter.HTML(),
    pages = [
    "Home"=>"index.md",
    "Optimizers"=>"optimizers.md",
    "Examples"=>"examples.md",
    ]
)

deploydocs(
    deps = Deps.pip("mkdocs", "python-markdown-math"),
    repo = "github.com/jacobcvt12/GradDescent.jl.git",
    julia = "1.0"
)


text:
@testset "Retry 429" begin
  println(testname("Retry on 429 tests"))
  print("  [  ] Retry settings ")
  retry_settings!(enabled=true)
  settings = retry_settings()
  @test settings["enabled"] == true
  println("\r  [OK] Retry settings")

  print("  [  ] 429 retry (MOCK) ")
  # cl_mock = Client("blaha", "blaha", "http://mock429.eu-gb.mybluemix.net/"; auth=false)
  # try
  #   db, created = createdb(cl_mock, database)
  # catch err
  #   @test err.message == "max retries reached"
  # end
  # println("\r  [OK] 429 retry (MOCK)")
end

max_stars_repo_name: xpqz/couchzilla

max_issues_repo_name: xpqz/couchzilla

max_forks_repo_name: xpqz/couchzilla


text:
@testset "activity.jl" begin
    # No Tests written for activity.jl on account of activity.jl not being written.
end


text:
# -*- coding: utf-8 -*-
# +
using Random

using Flux
using Flux.Data: DataLoader
using MLDatasets
using Images
using ProgressMeter

# +
Base.@kwdef mutable struct Args
    η = 0.05
    λ = 0
    batchsize = 128
    epochs = 5
    seed = 12345
    use_cuda = false
end

args = Args()
Random.seed!(args.seed)
ENV["DATADEPS_ALWAYS_ACCEPT"] = true

# +
using Flux
using Flux.Data: DataLoader
using MLDatasets
xtrain, ytrain = MLDatasets.MNIST(split=:train, Tx=Float32)[:]
xtest, ytest = MLDatasets.MNIST(split=:test, Tx=Float32)[:];xtrain = Flux.unsqueeze(xtrain, 3) # (28, 28, 60000) -> (28, 28, 1 , 60000)

xtest = Flux.unsqueeze(xtest, 3)   # (28, 28, 10000) -> (28, 28, 1, 10000)
ytrain = Flux.onehotbatch(ytrain, 0:9) # (60000,) -> (10, 60000)
ytest = Flux.onehotbatch(ytest, 0:9)   # (10000,) -> (10, 10000)
train_loader = DataLoader((xtrain, ytrain), batchsize = 128, shuffle = true)
test_loader = DataLoader((xtest, ytest), batchsize = 128);

# +
struct LeNet
    cnn_layer::Any
    mlp_layer::Any
    nclasses::Any
end

Flux.@functor LeNet (cnn_layer, mlp_layer) # cnn_layer と mlp_layer が学習パラメータであることを指定する

# https://github.com/FluxML/model-zoo/blob/master/vision/conv_mnist/conv_mnist.jl
# を一部改変
function create_model(imsize::Tuple{Int,Int,Int}, nclasses::Int)
    W, H, inC = imsize
    out_conv_size = (W ÷ 4 - 3, H ÷ 4 - 3, 16)
    cnn_layer = Chain(
        Conv((5, 5), inC => 6, relu),
        MaxPool((2, 2)),
        Conv((5, 5), 6 => 16, relu),
        MaxPool((2, 2)),
    )
    mlp_layer = Chain(
        Dense(prod(out_conv_size), 120, relu),
        Dense(120, 84, relu),
        Dense(84, nclasses),
    )
    LeNet(cnn_layer, mlp_layer, nclasses)
end

(net::LeNet)(x) = x |> net.cnn_layer |> Flux.flatten |> net.mlp_layer
# -

model = create_model((28, 28, 1), 10) |> f32
ps = Flux.params(model);
opt = Descent(0.05)
loss(ŷ, y) = Flux.Losses.logitcrossentropy(ŷ, y)

for e = 1:args.epochs
    @showprogress for (x, y) in train_loader
        gs = Flux.gradient(ps) do
            ŷ = model(x)
            loss(ŷ, y)
        end
        Flux.Optimise.update!(opt, ps, gs)
    end
    acc = sum(Flux.onecold(model(xtest)) .== Flux.onecold(ytest))
    acc /= size(ytest, 2)
    @info("acc", 100acc, "%")
end

x_test, y_test = first(test_loader);
img = x_test[:, :, :, 1]
label = Flux.onecold(y_test[:, 1]) - 1
println("pred:", Flux.onecold(model(x_test))[1] - 1)
println("actual:", label)
Gray.(dropdims(img, dims = 3) |> transpose)


text:
#=
 Copyright 2013 - 2015 Marco Nehmeier (nehmeier@informatik.uni-wuerzburg.de)
 Copyright 2015 Oliver Heimlich (oheim@posteo.de)

 Original author: Marco Nehmeier (unit tests in libieeep1788)
 Converted into portable ITL format by Oliver Heimlich with minor corrections.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
=#
#Language imports

#Test library imports
if VERSION < v"0.7.0-DEV.2004"
    using Base.Test
else
    using Test
end

#Arithmetic library imports
using IntervalArithmetic

#Preamble
setprecision(53)
setprecision(Interval, Float64)
setrounding(Interval, :tight)
# Set full format, and show decorations
@format full

@testset "minimal_cancelPlus_test" begin
    @test cancelplus(Interval(-Inf, -1.0), ∅) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, Inf), ∅) == entireinterval(Float64)
    @test cancelplus(entireinterval(Float64), ∅) == entireinterval(Float64)
    @test cancelplus(Interval(-Inf, -1.0), Interval(-5.0, 1.0)) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, Inf), Interval(-5.0, 1.0)) == entireinterval(Float64)
    @test cancelplus(entireinterval(Float64), Interval(-5.0, 1.0)) == entireinterval(Float64)
    @test cancelplus(Interval(-Inf, -1.0), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, Inf), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelplus(∅, Interval(1.0, Inf)) == entireinterval(Float64)
    @test cancelplus(∅, Interval(-Inf, 1.0)) == entireinterval(Float64)
    @test cancelplus(∅, entireinterval(Float64)) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, 5.0), Interval(1.0, Inf)) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, 5.0), Interval(-Inf, 1.0)) == entireinterval(Float64)
    @test cancelplus(Interval(-1.0, 5.0), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelplus(entireinterval(Float64), Interval(1.0, Inf)) == entireinterval(Float64)
    @test cancelplus(entireinterval(Float64), Interval(-Inf, 1.0)) == entireinterval(Float64)
    @test cancelplus(entireinterval(Float64), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelplus(Interval(-5.0, -1.0), Interval(1.0, 5.1)) == entireinterval(Float64)
    @test cancelplus(Interval(-5.0, -1.0), Interval(0.9, 5.0)) == entireinterval(Float64)
    @test cancelplus(Interval(-5.0, -1.0), Interval(0.9, 5.1)) == entireinterval(Float64)
    @test cancelplus(Interval(-10.0, 5.0), Interval(-5.0, 10.1)) == entireinterval(Float64)
    @test cancelplus(Interval(-10.0, 5.0), Interval(-5.1, 10.0)) == entireinterval(Float64)
    @test cancelplus(Interval(-10.0, 5.0), Interval(-5.1, 10.1)) == entireinterval(Float64)
    @test cancelplus(Interval(1.0, 5.0), Interval(-5.0, -0.9)) == entireinterval(Float64)
    @test cancelplus(Interval(1.0, 5.0), Interval(-5.1, -1.0)) == entireinterval(Float64)
    @test cancelplus(Interval(1.0, 5.0), Interval(-5.1, -0.9)) == entireinterval(Float64)
    @test cancelplus(Interval(-10.0, -1.0), ∅) == entireinterval(Float64)
    @test cancelplus(Interval(-10.0, 5.0), ∅) == entireinterval(Float64)
    @test cancelplus(Interval(1.0, 5.0), ∅) == entireinterval(Float64)
    @test cancelplus(∅, ∅) == ∅
    @test cancelplus(∅, Interval(1.0, 10.0)) == ∅
    @test cancelplus(∅, Interval(-5.0, 10.0)) == ∅
    @test cancelplus(∅, Interval(-5.0, -1.0)) == ∅
    @test cancelplus(Interval(-5.1, -0.0), Interval(0.0, 5.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelplus(Interval(-5.1, -1.0), Interval(1.0, 5.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelplus(Interval(-5.0, -0.9), Interval(1.0, 5.0)) == Interval(0.0, 0x1.9999999999998p-4)
    @test cancelplus(Interval(-5.1, -0.9), Interval(1.0, 5.0)) == Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4)
    @test cancelplus(Interval(-5.0, -1.0), Interval(1.0, 5.0)) == Interval(0.0, 0.0)
    @test cancelplus(Interval(-10.1, 5.0), Interval(-5.0, 10.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelplus(Interval(-10.0, 5.1), Interval(-5.0, 10.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelplus(Interval(-10.1, 5.1), Interval(-5.0, 10.0)) == Interval(-0x1.999999999998p-4, 0x1.999999999998p-4)
    @test cancelplus(Interval(-10.0, 5.0), Interval(-5.0, 10.0)) == Interval(0.0, 0.0)
    @test cancelplus(Interval(0.9, 5.0), Interval(-5.0, -1.0)) == Interval(-0x1.9999999999998p-4, 0.0)
    @test cancelplus(Interval(1.0, 5.1), Interval(-5.0, -1.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelplus(Interval(0.0, 5.1), Interval(-5.0, -0.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelplus(Interval(0.9, 5.1), Interval(-5.0, -1.0)) == Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4)
    @test cancelplus(Interval(1.0, 5.0), Interval(-5.0, -1.0)) == Interval(0.0, 0.0)
    @test cancelplus(Interval(0.0, 5.0), Interval(-5.0, -0.0)) == Interval(0.0, 0.0)
    @test cancelplus(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), Interval(-0x1.999999999999ap-4, -0x1.999999999999ap-4)) == Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0)
    @test cancelplus(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), Interval(-0x1.999999999999ap-4, 0.01)) == Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0)
    @test cancelplus(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == Interval(0x1.fffffffffffffp1023, Inf)
    @test cancelplus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == Interval(0.0, 0.0)
    @test cancelplus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023)) == Interval(0.0, 0x1p+971)
    @test cancelplus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023)) == Interval(-0x1p+971, 0.0)
    @test cancelplus(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == entireinterval(Float64)
    @test cancelplus(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == entireinterval(Float64)
    @test cancelplus(Interval(-0x1p+0, 0x1.fffffffffffffp-53), Interval(-0x1p+0, 0x1.ffffffffffffep-53)) == Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1)
    @test cancelplus(Interval(-0x1p+0, 0x1.ffffffffffffep-53), Interval(-0x1p+0, 0x1.fffffffffffffp-53)) == entireinterval(Float64)
end

@testset "minimal_cancelPlus_dec_test" begin
    @test cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(Interval(-5.0, 1.0), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(Interval(-5.0, 1.0), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, Inf), trv), DecoratedInterval(Interval(-5.0, 1.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, Inf), trv), DecoratedInterval(Interval(-5.0, 1.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-5.0, 1.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-5.0, 1.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, Inf), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, Inf), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-Inf, 1.0), trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-Inf, 1.0), trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, 5.0), dac), DecoratedInterval(Interval(1.0, Inf), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, 5.0), dac), DecoratedInterval(Interval(1.0, Inf), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, 5.0), def), DecoratedInterval(Interval(-Inf, 1.0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, 5.0), def), DecoratedInterval(Interval(-Inf, 1.0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-1.0, 5.0), com), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-1.0, 5.0), com), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(1.0, Inf), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(1.0, Inf), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-Inf, 1.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-Inf, 1.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(1.0, 5.1), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(1.0, 5.1), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(0.9, 5.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(0.9, 5.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.0, -1.0), def), DecoratedInterval(Interval(0.9, 5.1), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.0, -1.0), def), DecoratedInterval(Interval(0.9, 5.1), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.0), trv), DecoratedInterval(Interval(-5.0, 10.1), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.0), trv), DecoratedInterval(Interval(-5.0, 10.1), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-5.1, 10.0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-5.1, 10.0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(Interval(-5.1, 10.1), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(Interval(-5.1, 10.1), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(Interval(-5.0, -0.9), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(Interval(-5.0, -0.9), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.0), trv), DecoratedInterval(Interval(-5.1, -1.0), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.0), trv), DecoratedInterval(Interval(-5.1, -1.0), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(-5.1, -0.9), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(-5.1, -0.9), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, -1.0), trv), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, -1.0), trv), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.0), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.0), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.0), com), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.0), com), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(∅, trv)) == DecoratedInterval(∅, trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(∅, trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, 10.0), dac)) == DecoratedInterval(∅, trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, 10.0), dac))) == decoration(DecoratedInterval(∅, trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-5.0, 10.0), def)) == DecoratedInterval(∅, trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-5.0, 10.0), def))) == decoration(DecoratedInterval(∅, trv))
    @test cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-5.0, -1.0), com)) == DecoratedInterval(∅, trv)
    @test decoration(cancelplus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-5.0, -1.0), com))) == decoration(DecoratedInterval(∅, trv))
    @test cancelplus(DecoratedInterval(Interval(-5.1, -0.0), com), DecoratedInterval(Interval(0.0, 5.0), com)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.1, -0.0), com), DecoratedInterval(Interval(0.0, 5.0), com))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.1, -1.0), com), DecoratedInterval(Interval(1.0, 5.0), dac)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.1, -1.0), com), DecoratedInterval(Interval(1.0, 5.0), dac))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.0, -0.9), com), DecoratedInterval(Interval(1.0, 5.0), def)) == DecoratedInterval(Interval(0.0, 0x1.9999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.0, -0.9), com), DecoratedInterval(Interval(1.0, 5.0), def))) == decoration(DecoratedInterval(Interval(0.0, 0x1.9999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.1, -0.9), dac), DecoratedInterval(Interval(1.0, 5.0), trv)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.1, -0.9), dac), DecoratedInterval(Interval(1.0, 5.0), trv))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(1.0, 5.0), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(1.0, 5.0), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.1, 5.0), dac), DecoratedInterval(Interval(-5.0, 10.0), dac)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.1, 5.0), dac), DecoratedInterval(Interval(-5.0, 10.0), dac))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.1), def), DecoratedInterval(Interval(-5.0, 10.0), def)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.1), def), DecoratedInterval(Interval(-5.0, 10.0), def))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.1, 5.1), def), DecoratedInterval(Interval(-5.0, 10.0), trv)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.1, 5.1), def), DecoratedInterval(Interval(-5.0, 10.0), trv))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(-10.0, 5.0), def), DecoratedInterval(Interval(-5.0, 10.0), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-10.0, 5.0), def), DecoratedInterval(Interval(-5.0, 10.0), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(0.9, 5.0), trv), DecoratedInterval(Interval(-5.0, -1.0), dac)) == DecoratedInterval(Interval(-0x1.9999999999998p-4, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0.9, 5.0), trv), DecoratedInterval(Interval(-5.0, -1.0), dac))) == decoration(DecoratedInterval(Interval(-0x1.9999999999998p-4, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.1), trv), DecoratedInterval(Interval(-5.0, -1.0), def)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.1), trv), DecoratedInterval(Interval(-5.0, -1.0), def))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(0.0, 5.1), trv), DecoratedInterval(Interval(-5.0, -0.0), trv)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0.0, 5.1), trv), DecoratedInterval(Interval(-5.0, -0.0), trv))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(0.9, 5.1), com), DecoratedInterval(Interval(-5.0, -1.0), com)) == DecoratedInterval(Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0.9, 5.1), com), DecoratedInterval(Interval(-5.0, -1.0), com))) == decoration(DecoratedInterval(Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4), trv))
    @test cancelplus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(-5.0, -1.0), dac)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(-5.0, -1.0), dac))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(0.0, 5.0), def), DecoratedInterval(Interval(-5.0, -0.0), trv)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0.0, 5.0), def), DecoratedInterval(Interval(-5.0, -0.0), trv))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), com), DecoratedInterval(Interval(-0x1.999999999999ap-4, -0x1.999999999999ap-4), com)) == DecoratedInterval(Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), com), DecoratedInterval(Interval(-0x1.999999999999ap-4, -0x1.999999999999ap-4), com))) == decoration(DecoratedInterval(Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), dac), DecoratedInterval(Interval(-0x1.999999999999ap-4, 0.01), com)) == DecoratedInterval(Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), dac), DecoratedInterval(Interval(-0x1.999999999999ap-4, 0.01), com))) == decoration(DecoratedInterval(Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0), trv))
    @test cancelplus(DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(0x1.fffffffffffffp1023, Inf), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(0x1.fffffffffffffp1023, Inf), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), dac), DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(0.0, 0x1p+971), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), dac), DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(0.0, 0x1p+971), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), dac), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com)) == DecoratedInterval(Interval(-0x1p+971, 0.0), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), dac), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com))) == decoration(DecoratedInterval(Interval(-0x1p+971, 0.0), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), dac), DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), com)) == DecoratedInterval(Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), dac), DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), com))) == decoration(DecoratedInterval(Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1), trv))
    @test cancelplus(DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), def), DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelplus(DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), def), DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
end

@testset "minimal_cancelMinus_test" begin
    @test cancelminus(Interval(-Inf, -1.0), ∅) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, Inf), ∅) == entireinterval(Float64)
    @test cancelminus(entireinterval(Float64), ∅) == entireinterval(Float64)
    @test cancelminus(Interval(-Inf, -1.0), Interval(-1.0, 5.0)) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, Inf), Interval(-1.0, 5.0)) == entireinterval(Float64)
    @test cancelminus(entireinterval(Float64), Interval(-1.0, 5.0)) == entireinterval(Float64)
    @test cancelminus(Interval(-Inf, -1.0), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, Inf), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelminus(∅, Interval(-Inf, -1.0)) == entireinterval(Float64)
    @test cancelminus(∅, Interval(-1.0, Inf)) == entireinterval(Float64)
    @test cancelminus(∅, entireinterval(Float64)) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, 5.0), Interval(-Inf, -1.0)) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, 5.0), Interval(-1.0, Inf)) == entireinterval(Float64)
    @test cancelminus(Interval(-1.0, 5.0), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelminus(entireinterval(Float64), Interval(-Inf, -1.0)) == entireinterval(Float64)
    @test cancelminus(entireinterval(Float64), Interval(-1.0, Inf)) == entireinterval(Float64)
    @test cancelminus(entireinterval(Float64), entireinterval(Float64)) == entireinterval(Float64)
    @test cancelminus(Interval(-5.0, -1.0), Interval(-5.1, -1.0)) == entireinterval(Float64)
    @test cancelminus(Interval(-5.0, -1.0), Interval(-5.0, -0.9)) == entireinterval(Float64)
    @test cancelminus(Interval(-5.0, -1.0), Interval(-5.1, -0.9)) == entireinterval(Float64)
    @test cancelminus(Interval(-10.0, 5.0), Interval(-10.1, 5.0)) == entireinterval(Float64)
    @test cancelminus(Interval(-10.0, 5.0), Interval(-10.0, 5.1)) == entireinterval(Float64)
    @test cancelminus(Interval(-10.0, 5.0), Interval(-10.1, 5.1)) == entireinterval(Float64)
    @test cancelminus(Interval(1.0, 5.0), Interval(0.9, 5.0)) == entireinterval(Float64)
    @test cancelminus(Interval(1.0, 5.0), Interval(1.0, 5.1)) == entireinterval(Float64)
    @test cancelminus(Interval(1.0, 5.0), Interval(0.9, 5.1)) == entireinterval(Float64)
    @test cancelminus(Interval(-10.0, -1.0), ∅) == entireinterval(Float64)
    @test cancelminus(Interval(-10.0, 5.0), ∅) == entireinterval(Float64)
    @test cancelminus(Interval(1.0, 5.0), ∅) == entireinterval(Float64)
    @test cancelminus(∅, ∅) == ∅
    @test cancelminus(∅, Interval(-10.0, -1.0)) == ∅
    @test cancelminus(∅, Interval(-10.0, 5.0)) == ∅
    @test cancelminus(∅, Interval(1.0, 5.0)) == ∅
    @test cancelminus(Interval(-5.1, -0.0), Interval(-5.0, 0.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelminus(Interval(-5.1, -1.0), Interval(-5.0, -1.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelminus(Interval(-5.0, -0.9), Interval(-5.0, -1.0)) == Interval(0.0, 0x1.9999999999998p-4)
    @test cancelminus(Interval(-5.1, -0.9), Interval(-5.0, -1.0)) == Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4)
    @test cancelminus(Interval(-5.0, -1.0), Interval(-5.0, -1.0)) == Interval(0.0, 0.0)
    @test cancelminus(Interval(-10.1, 5.0), Interval(-10.0, 5.0)) == Interval(-0x1.999999999998p-4, 0.0)
    @test cancelminus(Interval(-10.0, 5.1), Interval(-10.0, 5.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelminus(Interval(-10.1, 5.1), Interval(-10.0, 5.0)) == Interval(-0x1.999999999998p-4, 0x1.999999999998p-4)
    @test cancelminus(Interval(-10.0, 5.0), Interval(-10.0, 5.0)) == Interval(0.0, 0.0)
    @test cancelminus(Interval(0.9, 5.0), Interval(1.0, 5.0)) == Interval(-0x1.9999999999998p-4, 0.0)
    @test cancelminus(Interval(-0.0, 5.1), Interval(0.0, 5.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelminus(Interval(1.0, 5.1), Interval(1.0, 5.0)) == Interval(0.0, 0x1.999999999998p-4)
    @test cancelminus(Interval(0.9, 5.1), Interval(1.0, 5.0)) == Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4)
    @test cancelminus(Interval(1.0, 5.0), Interval(1.0, 5.0)) == Interval(0.0, 0.0)
    @test cancelminus(Interval(-5.0, 1.0), Interval(-1.0, 5.0)) == Interval(-4.0, -4.0)
    @test cancelminus(Interval(-5.0, 0.0), Interval(-0.0, 5.0)) == Interval(-5.0, -5.0)
    @test cancelminus(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), Interval(0x1.999999999999ap-4, 0x1.999999999999ap-4)) == Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0)
    @test cancelminus(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), Interval(-0.01, 0x1.999999999999ap-4)) == Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0)
    @test cancelminus(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, -0x1.fffffffffffffp1023)) == Interval(0x1.fffffffffffffp1023, Inf)
    @test cancelminus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == Interval(0.0, 0.0)
    @test cancelminus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023)) == Interval(0.0, 0x1p+971)
    @test cancelminus(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023)) == Interval(-0x1p+971, 0.0)
    @test cancelminus(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == entireinterval(Float64)
    @test cancelminus(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023)) == entireinterval(Float64)
    @test cancelminus(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022)) == Interval(0.0, 0.0)
    @test cancelminus(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), Interval(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022)) == Interval(0x0.0000000000002p-1022, 0x0.0000000000002p-1022)
    @test cancelminus(Interval(0x1p-1022, 0x1.0000000000002p-1022), Interval(0x1p-1022, 0x1.0000000000001p-1022)) == Interval(0.0, 0x0.0000000000001p-1022)
    @test cancelminus(Interval(0x1p-1022, 0x1.0000000000001p-1022), Interval(0x1p-1022, 0x1.0000000000002p-1022)) == entireinterval(Float64)
    @test cancelminus(Interval(-0x1p+0, 0x1.fffffffffffffp-53), Interval(-0x1.ffffffffffffep-53, 0x1p+0)) == Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1)
    @test cancelminus(Interval(-0x1p+0, 0x1.ffffffffffffep-53), Interval(-0x1.fffffffffffffp-53, 0x1p+0)) == entireinterval(Float64)
end

@testset "minimal_cancelMinus_dec_test" begin
    @test cancelminus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-Inf, -1.0), dac), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, Inf), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-Inf, -1.0), trv), DecoratedInterval(Interval(-1.0, 5.0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-Inf, -1.0), trv), DecoratedInterval(Interval(-1.0, 5.0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, Inf), dac), DecoratedInterval(Interval(-1.0, 5.0), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, Inf), dac), DecoratedInterval(Interval(-1.0, 5.0), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-1.0, 5.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-1.0, 5.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-Inf, -1.0), def), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-Inf, -1.0), def), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, Inf), trv), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, Inf), trv), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-Inf, -1.0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-Inf, -1.0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-1.0, Inf), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-1.0, Inf), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, 5.0), dac), DecoratedInterval(Interval(-Inf, -1.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, 5.0), dac), DecoratedInterval(Interval(-Inf, -1.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, 5.0), def), DecoratedInterval(Interval(-1.0, Inf), trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, 5.0), def), DecoratedInterval(Interval(-1.0, Inf), trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-1.0, 5.0), com), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-1.0, 5.0), com), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-Inf, -1.0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-Inf, -1.0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-1.0, Inf), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(Interval(-1.0, Inf), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(entireinterval(Float64), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(entireinterval(Float64), def), DecoratedInterval(entireinterval(Float64), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(-5.1, -1.0), trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(-5.1, -1.0), trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(-5.0, -0.9), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, -1.0), dac), DecoratedInterval(Interval(-5.0, -0.9), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, -1.0), def), DecoratedInterval(Interval(-5.1, -0.9), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, -1.0), def), DecoratedInterval(Interval(-5.1, -0.9), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.0), trv), DecoratedInterval(Interval(-10.1, 5.0), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.0), trv), DecoratedInterval(Interval(-10.1, 5.0), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-10.0, 5.1), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-10.0, 5.1), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(Interval(-10.1, 5.1), trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(Interval(-10.1, 5.1), trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(Interval(0.9, 5.0), def)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(Interval(0.9, 5.0), def))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.0), trv), DecoratedInterval(Interval(1.0, 5.1), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.0), trv), DecoratedInterval(Interval(1.0, 5.1), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.0), com), DecoratedInterval(Interval(0.9, 5.1), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.0), com), DecoratedInterval(Interval(0.9, 5.1), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, -1.0), com), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, -1.0), com), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.0), dac), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(∅, trv)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.0), def), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(∅, trv)) == DecoratedInterval(∅, trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(∅, trv))) == decoration(DecoratedInterval(∅, trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-10.0, -1.0), com)) == DecoratedInterval(∅, trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-10.0, -1.0), com))) == decoration(DecoratedInterval(∅, trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-10.0, 5.0), dac)) == DecoratedInterval(∅, trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(-10.0, 5.0), dac))) == decoration(DecoratedInterval(∅, trv))
    @test cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, 5.0), def)) == DecoratedInterval(∅, trv)
    @test decoration(cancelminus(DecoratedInterval(∅, trv), DecoratedInterval(Interval(1.0, 5.0), def))) == decoration(DecoratedInterval(∅, trv))
    @test cancelminus(DecoratedInterval(Interval(-5.1, -0.0), com), DecoratedInterval(Interval(-5.0, 0.0), com)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.1, -0.0), com), DecoratedInterval(Interval(-5.0, 0.0), com))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.1, -1.0), dac), DecoratedInterval(Interval(-5.0, -1.0), com)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.1, -1.0), dac), DecoratedInterval(Interval(-5.0, -1.0), com))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, -0.9), def), DecoratedInterval(Interval(-5.0, -1.0), com)) == DecoratedInterval(Interval(0.0, 0x1.9999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, -0.9), def), DecoratedInterval(Interval(-5.0, -1.0), com))) == decoration(DecoratedInterval(Interval(0.0, 0x1.9999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.1, -0.9), trv), DecoratedInterval(Interval(-5.0, -1.0), com)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.1, -0.9), trv), DecoratedInterval(Interval(-5.0, -1.0), com))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.9999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(-5.0, -1.0), dac)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, -1.0), com), DecoratedInterval(Interval(-5.0, -1.0), dac))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.1, 5.0), dac), DecoratedInterval(Interval(-10.0, 5.0), dac)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.1, 5.0), dac), DecoratedInterval(Interval(-10.0, 5.0), dac))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.1), def), DecoratedInterval(Interval(-10.0, 5.0), dac)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.1), def), DecoratedInterval(Interval(-10.0, 5.0), dac))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.1, 5.1), trv), DecoratedInterval(Interval(-10.0, 5.0), def)) == DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.1, 5.1), trv), DecoratedInterval(Interval(-10.0, 5.0), def))) == decoration(DecoratedInterval(Interval(-0x1.999999999998p-4, 0x1.999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-10.0, 5.0), def)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-10.0, 5.0), com), DecoratedInterval(Interval(-10.0, 5.0), def))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(0.9, 5.0), dac), DecoratedInterval(Interval(1.0, 5.0), def)) == DecoratedInterval(Interval(-0x1.9999999999998p-4, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0.9, 5.0), dac), DecoratedInterval(Interval(1.0, 5.0), def))) == decoration(DecoratedInterval(Interval(-0x1.9999999999998p-4, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-0.0, 5.1), def), DecoratedInterval(Interval(0.0, 5.0), def)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0.0, 5.1), def), DecoratedInterval(Interval(0.0, 5.0), def))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.1), trv), DecoratedInterval(Interval(1.0, 5.0), trv)) == DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.1), trv), DecoratedInterval(Interval(1.0, 5.0), trv))) == decoration(DecoratedInterval(Interval(0.0, 0x1.999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(0.9, 5.1), com), DecoratedInterval(Interval(1.0, 5.0), trv)) == DecoratedInterval(Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0.9, 5.1), com), DecoratedInterval(Interval(1.0, 5.0), trv))) == decoration(DecoratedInterval(Interval(-0x1.9999999999998p-4, 0x1.999999999998p-4), trv))
    @test cancelminus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(1.0, 5.0), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(1.0, 5.0), dac), DecoratedInterval(Interval(1.0, 5.0), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, 1.0), def), DecoratedInterval(Interval(-1.0, 5.0), def)) == DecoratedInterval(Interval(-4.0, -4.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, 1.0), def), DecoratedInterval(Interval(-1.0, 5.0), def))) == decoration(DecoratedInterval(Interval(-4.0, -4.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-5.0, 0.0), trv), DecoratedInterval(Interval(-0.0, 5.0), trv)) == DecoratedInterval(Interval(-5.0, -5.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-5.0, 0.0), trv), DecoratedInterval(Interval(-0.0, 5.0), trv))) == decoration(DecoratedInterval(Interval(-5.0, -5.0), trv))
    @test cancelminus(DecoratedInterval(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), com), DecoratedInterval(Interval(0x1.999999999999ap-4, 0x1.999999999999ap-4), com)) == DecoratedInterval(Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x1.ffffffffffffp+0, 0x1.ffffffffffffp+0), com), DecoratedInterval(Interval(0x1.999999999999ap-4, 0x1.999999999999ap-4), com))) == decoration(DecoratedInterval(Interval(0x1.e666666666656p+0, 0x1.e666666666657p+0), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), def), DecoratedInterval(Interval(-0.01, 0x1.999999999999ap-4), dac)) == DecoratedInterval(Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.999999999999ap-4, 0x1.ffffffffffffp+0), def), DecoratedInterval(Interval(-0.01, 0x1.999999999999ap-4), dac))) == decoration(DecoratedInterval(Interval(-0x1.70a3d70a3d70bp-4, 0x1.e666666666657p+0), trv))
    @test cancelminus(DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, -0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(0x1.fffffffffffffp1023, Inf), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, -0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(0x1.fffffffffffffp1023, Inf), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com)) == DecoratedInterval(Interval(0.0, 0x1p+971), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com))) == decoration(DecoratedInterval(Interval(0.0, 0x1p+971), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(Interval(-0x1p+971, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(Interval(-0x1p+971, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.ffffffffffffep+1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1.ffffffffffffep+1023, 0x1.fffffffffffffp1023), com), DecoratedInterval(Interval(-0x1.fffffffffffffp1023, 0x1.fffffffffffffp1023), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com), DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com)) == DecoratedInterval(Interval(0.0, 0.0), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com), DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com))) == decoration(DecoratedInterval(Interval(0.0, 0.0), trv))
    @test cancelminus(DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com), DecoratedInterval(Interval(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022), dac)) == DecoratedInterval(Interval(0x0.0000000000002p-1022, 0x0.0000000000002p-1022), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), com), DecoratedInterval(Interval(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022), dac))) == decoration(DecoratedInterval(Interval(0x0.0000000000002p-1022, 0x0.0000000000002p-1022), trv))
    @test cancelminus(DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000002p-1022), dac), DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000001p-1022), dac)) == DecoratedInterval(Interval(0.0, 0x0.0000000000001p-1022), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000002p-1022), dac), DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000001p-1022), dac))) == decoration(DecoratedInterval(Interval(0.0, 0x0.0000000000001p-1022), trv))
    @test cancelminus(DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000001p-1022), def), DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000002p-1022), com)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000001p-1022), def), DecoratedInterval(Interval(0x1p-1022, 0x1.0000000000002p-1022), com))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), com), DecoratedInterval(Interval(-0x1.ffffffffffffep-53, 0x1p+0), dac)) == DecoratedInterval(Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1p+0, 0x1.fffffffffffffp-53), com), DecoratedInterval(Interval(-0x1.ffffffffffffep-53, 0x1p+0), dac))) == decoration(DecoratedInterval(Interval(-0x1.fffffffffffffp-1, -0x1.ffffffffffffep-1), trv))
    @test cancelminus(DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), def), DecoratedInterval(Interval(-0x1.fffffffffffffp-53, 0x1p+0), dac)) == DecoratedInterval(entireinterval(Float64), trv)
    @test decoration(cancelminus(DecoratedInterval(Interval(-0x1p+0, 0x1.ffffffffffffep-53), def), DecoratedInterval(Interval(-0x1.fffffffffffffp-53, 0x1p+0), dac))) == decoration(DecoratedInterval(entireinterval(Float64), trv))
end
# FactCheck.exitstatus()


text:
import PyPlot: plot

import Basis: nodes
import Weno: coefficient_matrices, oscillation_indicator, weno

function plot_weno(wh, var, N)
  n = size(wh)[1]
  x = float(repeat(0:n-1, inner=N+1))
  for i = 1:n
    x[1+(i-1)*(N+1) : i*(N+1)] += nodes(N)
  end
  y = zeros(n*(N+1))
  for i = 1:n
    for j = 1:N+1
      y[(i-1)*(N+1)+j] = wh[i, 1, 1, j, var]
    end
  end
  plot(x,y)
end

function main(u, N)
  M1,M2,M3,M4 = coefficient_matrices(N)
  Σ = oscillation_indicator(N)
  chΣT = chol(Σ)'
  @time weno(u, N, M1, M2, M3, M4, chΣT)
end

function sin_cos_test()
  u = rand(91,1,1,18)
  u[:,1,1,1] = sin(0:0.1:9)
  u[:,1,1,2] = cos(0:0.1:9)
  main(u,2)
  wh = main(u,2)
  plot_weno(wh,1,2)
  plot_weno(wh,2,2)
end

max_stars_repo_name: haranjackson/Julia-WENO


text:
using Chipmunk
# Using Debug draw requires SFML.jl
import SFML

window = SFML.RenderWindow("Debug draw!", 800, 600)
SFML.set_framerate_limit(window, 60)

gravity = Vect(0, -100)
body = Body(1, 1)
set_position(body, Vect(400, 0))
shape = CircleShape(body, 40, Vect(0, 0))

space = Space()
set_gravity(space, gravity)

add_body(space, body)
add_shape(space, shape)

timestep = 1./60
while true
    step(space, timestep)
    # Debug draw
    debug_draw(space, window, clear_and_display=true)
    println("Body position: $(get_position(body))")
end


text:
"""
    latexoperation(ex::Expr, prevOp::AbstractArray)

Translate a simple operation given by `ex` to LaTeX maths syntax.
This uses the information about the previous operations to decide if
a parenthesis is needed.

"""
function latexoperation(ex::Expr, prevOp::AbstractArray; cdot=true, kwargs...)
    op = ex.args[1]
    convertSubscript!(ex)
    args = map(i -> i isa Number ? latexraw(i; kwargs...) : i, ex.args)

    if op in [:/, :./]
        return "\\frac{$(args[2])}{$(args[3])}"

    elseif op in [:*, :.*]
        str=""
        for i in 2:length(args)
            arg = args[i]
            prevOp[i] in [:+, :-, :±]  && (arg = "\\left( $arg \\right)")
            str = string(str, arg)
            i != length(args) && (str *= cdot ? " \\cdot " : " ")
        end
        return str

    elseif op in [:+, :.+]
        str = join(args[2:end], " + ")
        str = replace(str, "+  -"=>"-")
        str = replace(str, "+ -"=>"-")
        return str

    elseif op in [:±, :.±]
        return "$(args[2]) \\pm $(args[3])"

    elseif op in [:-, :.-]
        if length(args) == 2
            if prevOp[2] == :none && string(args[2])[1] == '-'
                return " + " * string(args[2])[2:end]
            elseif prevOp[2] == :none && string(args[2])[1] == '+'
                return " - " * string(args[2])[2:end]
            elseif prevOp[2] in [:+, :-, :±]
                return " - \\left( $(args[2]) \\right)"
            end
            return " - $(args[2])"
        end
        prevOp[3] in [:+, :-, :±] &&  (args[3] = "\\left( $(args[3]) \\right)")

        if prevOp[3] == :none && string(args[3])[1] == '-'
            return "$(args[2]) + " * string(args[3])[2:end]
        end
        return "$(args[2]) - $(args[3])"

    elseif op in [:^, :.^]
        #isa(args[2], String) && (args[2]="($(args[2]))")
        if prevOp[2] in trigonometric_functions
            str = get(function2latex, prevOp[2], "\\$(prevOp[2])")
            return replace(args[2], str => "$(str)^{$(args[3])}")
        end
        prevOp[2] != :none  && (args[2]="\\left( $(args[2]) \\right)")
        return "$(args[2])^{$(args[3])}"
    elseif ex.head == :(=) && length(args) == 2
        return "$(args[1]) = $(args[2])"
    end

    if ex.head == :.
        ex.head = :call
        # op = string(op, ".") ## Signifies broadcasting.
    end

    string(op)[1] == '.' && (op = Symbol(string(op)[2:end]))

    # infix_operators = [:<, :>, Symbol("=="), :<=, :>=, :!=]
    comparison_operators = Dict(
        :< => "\\lt",
        :.< => "\\lt",
        :> => "\\gt",
        :.> => "\\gt",
        Symbol("==") => "=",
        Symbol(".==") => "=",
        :<= => "\\leq",
        :.<= => "\\leq",
        :>= => "\\geq",
        :.>= => "\\geq",
        :!= => "\\neq",
        :.!= => "\\neq",
        )

    if op in keys(comparison_operators) && length(args) == 3
        str = "$(args[2]) $(comparison_operators[op]) $(args[3])"
        str = "\\left( $str \\right)"
        return str
    end

    ### Check for chained comparison operators
    if ex.head == :comparison && Symbol.(args[2:2:end]) ⊆ keys(comparison_operators)
        str = join([isodd(i) ? "$var" : comparison_operators[var] for (i, var) in enumerate(Symbol.(args))], " ")
        str = "\\left( $str \\right)"
        return str
    end

    if op in keys(function2latex)
        return "$(function2latex[op])\\left( $(join(args[2:end], ", ")) \\right)"
    end

    op == :sqrt && return "\\$op{$(args[2])}"
    op == :abs && return "\\left\\|$(args[2])\\right\\|"
    op == :exp && return "e^{$(args[2])}"

    if ex.head == :ref
        argstring = join(args[2:end], ", ")
        return "\\mathrm{$op}\\left[$argstring\\right]"
    end

    if ex.head == :call
        if args[2] isa String && occursin("=", args[2])
            return "\\mathrm{$op}\\left( $(join(args[3:end], ", ")); $(args[2]) \\right)"
        else
            return "\\mathrm{$op}\\left( $(join(args[2:end], ", ")) \\right)"
        end
    end

    if ex.head == :tuple
        # return "\\left(" * join(ex.args, ", ") * "\\right)"
        return join(ex.args, ", ")
    end

    ex.head == Symbol("'") && return "$(args[1])'"

    ## Enable the parsing of kwargs in a function definition
    ex.head == :kw && return "$(args[1]) = $(args[2])"
    ex.head == :parameters && return join(args, ", ")

    ## Use the last expression in a block.
    ## This is somewhat shady but it helps with latexifying functions.
    ex.head == :block && return args[end]

    ## Sort out type annotations. Mainly for function arguments.
    ex.head == :(::) && length(args) == 1 && return "::$(args[1])"
    ex.head == :(::) && length(args) == 2 && return "$(args[1])::$(args[2])"

    ## if we have reached this far without a return, then error.
    error("Latexify.jl's latexoperation does not know what to do with one of the
          expressions provides ($ex).")
    return ""
end

latexoperation(sym::Symbol, prevOp::AbstractArray; kwargs...) = "$sym"

function convertSubscript!(ex::Expr)
    for i in 1:length(ex.args)
        arg = ex.args[i]
        if arg isa Symbol
            ex.args[i] = convertSubscript(arg)
        end
    end
    return nothing
end

function convertSubscript(str::String)
    if occursin("_", str)
        subscriptList = split(str, "_")
        subscript = join(subscriptList[2:end], "\\_")
        result = "$(subscriptList[1])_{$subscript}"
    else
        result = str
    end
    return result
end

convertSubscript(sym::Symbol) = convertSubscript(string(sym))