<commit_before>function get_test_trajdata(roadway::Roadway)
    trajdata = Trajdata(0.1)

    trajdata.defs[1] = VehicleDef(AgentClass.CAR, 5.0, 3.0)
    trajdata.defs[2] = VehicleDef(AgentClass.CAR, 5.0, 3.0)

    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(0.0,0.0,0.0), roadway, 10.0), 1)) # car 1, frame 1
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(3.0,0.0,0.0), roadway, 20.0), 2)) # car 2, frame 1
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(1.0,0.0,0.0), roadway, 10.0), 1)) # car 1, frame 2
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(5.0,0.0,0.0), roadway, 20.0), 2)) # car 2, frame 2

    push!(trajdata.frames, RecordFrame(1,2))
    push!(trajdata.frames, RecordFrame(3,4))

    trajdata
end

@testset "1d state" begin 
    s = State1D(0.0, 0.0)
    path, io = mktemp()
    write(io, MIME"text/plain"(), s)
    close(io)
    io = open(path)
    s2 = read(io, MIME"text/plain"(), State1D)
    close(io)
    @test s == s2 

    veh = Vehicle1D(s, VehicleDef(), 1)
    scene = Scene1D()
    push!(scene, veh)
    scene2 = Scene1D([veh])
    @test scene[1].state.s == 0.0
    @test first(scene2.entities) == first(scene.entities)
    @test scene2.n == scene.n == 1
    @test get_center(veh) == 0.0
    @test get_footpoint(veh) == 0.0
    @test get_front(veh) == veh.def.length/2
    @test get_rear(veh) == - veh.def.length/2

end

@testset "VehicleState" begin 
    s = VehicleState(VecSE2(0.0,0.0,0.0), Frenet(NULL_ROADINDEX, 0.0, 0.0, 0.0), 10.0)
    @test isapprox(get_vel_s(s), 10.0)
    @test isapprox(get_vel_t(s),  0.0)
    show(IOBuffer(), s.posF)
    show(IOBuffer(), s)

    s = VehicleState(VecSE2(0.0,0.0,0.0), Frenet(NULL_ROADINDEX, 0.0, 0.0, 0.1), 10.0)
    @test isapprox(get_vel_s(s), 10.0*cos(0.1))
    @test isapprox(get_vel_t(s), 10.0*sin(0.1))
    
    vehdef = VehicleDef(AgentClass.CAR, 5.0, 3.0)
    veh = Vehicle(s, vehdef, 1)
    @test isapprox(get_footpoint(veh), VecSE2(0.0,0.0,0.0))
    show(IOBuffer(), vehdef)
    show(IOBuffer(), veh)

    ri = RoadIndex(CurveIndex(1,0.1), LaneTag(1,2))
    @test isapprox(Frenet(ri, 0.0, 0.0, 0.1), Frenet(ri, 0.0, 0.0, 0.1))
    @test VehicleState(VecSE2(0.1,0.2,0.3), 1.0) == VehicleState(VecSE2(0.1,0.2,0.3), NULL_FRENET, 1.0)
end

@testset "scene" begin 
    roadway = get_test_roadway()
    trajdata = get_test_trajdata(roadway)

    vehstate = VehicleState(VecSE2(0.0, 0.0, 0.0), roadway, 0.0)
    veh = Vehicle(vehstate, VehicleDef(), 1)
    scene1 = Scene()
    push!(scene1, veh)
    scene2 = Scene([veh])
    @test first(scene1.entities) == first(scene2.entities)
    @test scene1.n == scene2.n

    io = IOBuffer()
    show(io, scene1)
    close(io)

    veh2 = Entity(vehstate, BicycleModel(VehicleDef()), 1)
    veh3 = convert(Vehicle, veh2)
    @test veh3 == veh

    rec = SceneRecord(1, 0.5)
    rec = SceneRecord(1, 0.5, 10)
<commit_msg>state tests<commit_after>function get_test_trajdata(roadway::Roadway)
    trajdata = Trajdata(0.1)

    trajdata.defs[1] = VehicleDef(AgentClass.CAR, 5.0, 3.0)
    trajdata.defs[2] = VehicleDef(AgentClass.CAR, 5.0, 3.0)

    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(0.0,0.0,0.0), roadway, 10.0), 1)) # car 1, frame 1
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(3.0,0.0,0.0), roadway, 20.0), 2)) # car 2, frame 1
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(1.0,0.0,0.0), roadway, 10.0), 1)) # car 1, frame 2
    push!(trajdata.states, RecordState{VehicleState, Int64}(VehicleState(VecSE2(5.0,0.0,0.0), roadway, 20.0), 2)) # car 2, frame 2

    push!(trajdata.frames, RecordFrame(1,2))
    push!(trajdata.frames, RecordFrame(3,4))

    trajdata
end

@testset "1d state" begin 
    s = State1D(0.0, 0.0)
    path, io = mktemp()
    write(io, MIME"text/plain"(), s)
    close(io)
    io = open(path)
    s2 = read(io, MIME"text/plain"(), State1D)
    close(io)
    @test s == s2 

    veh = Vehicle1D(s, VehicleDef(), 1)
    scene = Scene1D()
    push!(scene, veh)
    scene2 = Scene1D([veh])
    @test scene[1].state.s == 0.0
    @test first(scene2.entities) == first(scene.entities)
    @test scene2.n == scene.n == 1
    @test get_center(veh) == 0.0
    @test get_footpoint(veh) == 0.0
    @test get_front(veh) == veh.def.length/2
    @test get_rear(veh) == - veh.def.length/2

end

@testset "VehicleState" begin 
    s = VehicleState(VecSE2(0.0,0.0,0.0), Frenet(NULL_ROADINDEX, 0.0, 0.0, 0.0), 10.0)
    @test isapprox(get_vel_s(s), 10.0)
    @test isapprox(get_vel_t(s),  0.0)
    show(IOBuffer(), s.posF)
    show(IOBuffer(), s)

    s = VehicleState(VecSE2(0.0,0.0,0.0), Frenet(NULL_ROADINDEX, 0.0, 0.0, 0.1), 10.0)
    @test isapprox(get_vel_s(s), 10.0*cos(0.1))
    @test isapprox(get_vel_t(s), 10.0*sin(0.1))
    
    vehdef = VehicleDef(AgentClass.CAR, 5.0, 3.0)
    veh = Vehicle(s, vehdef, 1)
    @test isapprox(get_footpoint(veh), VecSE2(0.0,0.0,0.0))
    show(IOBuffer(), vehdef)
    show(IOBuffer(), veh)

    ri = RoadIndex(CurveIndex(1,0.1), LaneTag(1,2))
    @test isapprox(Frenet(ri, 0.0, 0.0, 0.1), Frenet(ri, 0.0, 0.0, 0.1))
    @test VehicleState(VecSE2(0.1,0.2,0.3), 1.0) == VehicleState(VecSE2(0.1,0.2,0.3), NULL_FRENET, 1.0)

    @test get_front(veh).x == vehdef.length/2
    @test get_rear(veh).x == -vehdef.length/2
end

@testset "scene" begin 
    roadway = get_test_roadway()
    trajdata = get_test_trajdata(roadway)

    s1 = VehicleState(VecSE2(0.0, 0.0, 0.0), roadway, 0.0)
    s2 = VehicleState(VecSE2(5.0, 0.0, 0.0), roadway, 0.0)
    s3 = lerp(s1, s2, 0.5, roadway)
    @test s3.posG.x == 2.5
    @test s3.posF.s == 2.5

    vehstate = VehicleState(VecSE2(0.0, 0.0, 0.0), roadway, 0.0)
    vehstate1 = VehicleState(VecSE2(0.0, 0.0, 0.0), roadway[LaneTag(1,1)], roadway, 0.0)
    @test vehstate1 == vehstate
    veh = Vehicle(vehstate, VehicleDef(), 1)
    scene1 = Scene()
    push!(scene1, veh)
    scene2 = Scene([veh])
    @test first(scene1.entities) == first(scene2.entities)
    @test scene1.n == scene2.n

    io = IOBuffer()
    show(io, scene1)
    close(io)

    veh2 = Entity(vehstate, BicycleModel(VehicleDef()), 1)
    veh3 = convert(Vehicle, veh2)
    @test veh3 == veh

    rec = SceneRecord(1, 0.5)
    rec = SceneRecord(1, 0.5, 10)

{'fraction_non_alphanumeric': 0.18247601069686958, 'fraction_numerical': 0.07865345288658172, 'mean_word_length': 3.4774647887323944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4077787', 'n_tokens_mistral': 2995, 'n_tokens_neox': 2776, 'n_words': 506}