Ejemplo n.º 1
0
def test_eq_spill_container_pair(uncertain):
    """
    SpillContainerPair inherits from SpillContainer so it should
    compute __eq__ and __ne__ in the same way - test it here

    Incomplete - this doesn't currently work!
    Test fails if uncertainty is on whether particles are released or not
    This is because 'id' of uncertain spills do not match and one should not
    expect them to match.

    todo: remove 'id' property as a check for equality. This requires changes
          in persisting logic. Update persistence then revisit this test
          and simplify it
    """
    (sp1, sp2) = get_eq_spills()

    # windages array will not match after elements are released so lets not
    # add any more types to data_arrays for this test. Just look at base
    # array_types for SpillContainer's and ensure the data matches for them
    sp1.element_type = elements.ElementType()
    sp2.element_type = elements.ElementType()

    scp1 = SpillContainerPair(uncertain)  # uncertainty is on
    scp1.add(sp1)

    scp2 = SpillContainerPair(uncertain)
    if uncertain:
        u_sp1 = [scp1.items()[1].spills[spill.id] for spill in
                 scp1.items()[1].spills][0]

        u_sp2 = PointLineSource.new_from_dict(u_sp1.to_dict('create'))

        scp2.add((sp2, u_sp2))
    else:
        scp2.add(sp2)

    for sc in zip(scp1.items(), scp2.items()):
        sc[0].prepare_for_model_run()
        sc[0].release_elements(360, sp1.release_time)
        sc[1].prepare_for_model_run()
        sc[1].release_elements(360, sp2.release_time)

    assert scp1 == scp2
Ejemplo n.º 2
0
def get_eq_spills():
    """
    returns a tuple of identical PointLineSource objects

    todo: The spill's element_type is forced to be ElementType() since
    it is not being persisted and the default (Floating()) uses randomly
    generated values for initial data array values and these will not match for
    the two spills. Fix this be persisting element_type attribute and making
    min and max windage_range equal so windages are the same.
    """

    num_elements = 10
    release_time = datetime(2000, 1, 1, 1)

    spill = PointLineSource(num_elements,
                            (28, -75, 0),
                            release_time,
                            element_type=elements.ElementType())
    spill2 = PointLineSource.new_from_dict(spill.to_dict('create'))
    spill2.element_type = elements.ElementType()

    return (spill, spill2)