def test_encode_csv_vector_no_gen(): num_bins = 30 num_beams = 4 vel = EarthVelocity(num_bins, num_beams) # Populate data val = 2.0 for beam in range(vel.element_multiplier): for bin_num in range(vel.num_elements): vel.Velocities[bin_num][beam] = val vel.Magnitude, vel.Direction = EarthVelocity.generate_vectors( vel.Velocities) vel.remove_vessel_speed(-1.3, -1.4, 0.3) dt = datetime.datetime.now() # Create CSV lines result = vel.encode_csv(dt, 'A', 1, 1.3, 1.0) # Check the csv data for line in result: if bool(re.search(Ensemble.CSV_MAG, line[0])): assert bool(re.search(str(2.477), line[0])) assert bool(re.search(Ensemble.CSV_MAG, line[0])) elif bool(re.search(Ensemble.CSV_DIR, line[0])): assert bool(re.search(str(49.3987), line[0])) assert bool(re.search(Ensemble.CSV_DIR, line[0])) elif bool(re.search(Ensemble.CSV_EARTH_VEL, line[0])): assert True else: assert False
def test_vectors(): earth = EarthVelocity(3, 4) earth.Velocities.clear() earth.Velocities.append([1.33, 1.45, 0.3, 0.0]) earth.Velocities.append([1.33, 1.45, 0.3, 0.0]) earth.Velocities.append([1.33, 1.45, 0.3, 0.0]) earth.remove_vessel_speed(-1.1, -1.2, -0.1) mag, dir = EarthVelocity.generate_vectors(earth.Velocities) assert 3 == len(mag) assert 3 == len(dir) assert 0.394 == pytest.approx(mag[0], 0.01) assert 42.614 == pytest.approx(dir[0], 0.01) assert 0.394 == pytest.approx(mag[1], 0.01) assert 42.614 == pytest.approx(dir[1], 0.01) assert 0.394 == pytest.approx(mag[2], 0.01) assert 42.614 == pytest.approx(dir[2], 0.01)