def __init__( self, calendar: "Calendar", ymd: Tuple[int, int, int], hours: Real = Sexagesimal(12), ): """ :param calendar: Calendar used in this date. :type calendar: Calendar :param ymd: Year, month and days, expressed in the specified calendar. :type ymd: Tuple[int, int, int] :param hours: Number of hours, defaults to Sexagesimal(12); :type hours: Real, optional """ if not 0 <= float(hours) < 24: raise ValueError("Time must be in the range [0;24,0[") self._calendar = calendar self._ymd = ymd self._hours = ( hours.resize(1) if isinstance(hours, Sexagesimal) else Sexagesimal.from_float(float(hours), 2) ) self._jdn = calendar.jdn_at_ymd(*ymd) - 0.5 + hours_to_day(hours)
def test_comparisons(x): s = Sexagesimal("1, 2; 30") xs = Sexagesimal.from_float(x, 1) for comp in (op.lt, op.le, op.eq, op.ne, op.ge, op.gt): if comp(float(s), x): assert comp(s, xs) else: assert not comp(s, xs)
assert isinstance(value, Quantity) assert value.unit is u.degree assert isinstance(value.value, Sexagesimal) @given(gen_table_strategy) def test_loc_slice(tab: HTable): sliced = tab.loc[tab["A"][1] :] assert not isinstance(sliced, HTable) or len(sliced) == len(tab) - 1 sin_table = HTable( [ list(Sexagesimal.range(91)), [round(Sexagesimal.from_float(np.sin(x * np.pi / 180), 3)) for x in range(91)], ], names=("Arg", "Val"), index="Arg", ) sin_table_grid = sin_table[ [i for i in range(91) if i <= 60 and i % 12 == 0 or i > 60 and i % 6 == 0] ] def test_based_fill(): sin_table_pop_euclidean = sin_table_grid.populate(list(Sexagesimal.range(91))) sin_table_pop_euclidean.fill("distributed_convex") assert len(sin_table_pop_euclidean) == 91
def test_init(): assert (Sexagesimal( (1, 2, 31), (6, ), sign=-1, remainder=Decimal("0.3")).__repr__() == "-01,02,31 ; 06 |r0.3") # From float assert Sexagesimal.from_float(-0.016666666666666666, 2) == -Sexagesimal( (0, ), (1, )) assert Sexagesimal.from_float(0.5, 4).equals(Sexagesimal("0; 30, 0, 0, 0")) with pytest.raises(TypeError): Sexagesimal.from_float("s", 1) # From int assert Sexagesimal.from_int(5, 2) == Sexagesimal(5) with pytest.raises(TypeError): Sexagesimal.from_int("s") # From Decimal assert Sexagesimal.from_decimal(Decimal(5), 2) == Sexagesimal(5) with pytest.raises(TypeError): Sexagesimal.from_decimal(5, 1) # From Fraction assert Sexagesimal.from_fraction(Fraction(5, 1)).equals(Sexagesimal(5)) assert Sexagesimal.from_fraction(Fraction(5, 2)) == Sexagesimal("2;30") with pytest.raises(TypeError): Sexagesimal.from_fraction(5) # From str assert Sexagesimal("21,1,6,3;34") == Sexagesimal((21, 1, 6, 3), (34, )) assert Sexagesimal("0,0,0,0;").equals(Sexagesimal(0)) with pytest.raises(TypeError): Sexagesimal._from_string(5) with pytest.raises(EmptyStringException): Sexagesimal("") with pytest.raises(TooManySeparators): Sexagesimal("1;2;3") # From Sequence with pytest.raises(IllegalBaseValueError) as err: Sexagesimal((-6, 3), ()) assert "should be in the range" in str(err.value) with pytest.raises(IllegalFloatError) as err: Sexagesimal((0.3, 5), (6, 8)) assert "An illegal float" in str(err.value) # From BasedReal assert Sexagesimal(Historical("3;15"), 1).equals(Sexagesimal("3;15")) class MNumber(BasedReal, base=([5, 2], [3, 4])): pass n = MNumber.from_float(234.6777, 0) assert Sexagesimal(n, 3) == Sexagesimal.from_float(float(n), 3) # From multiple ints with pytest.raises(ValueError): Sexagesimal(3, 5, remainder=Decimal(-5)) with pytest.raises(ValueError): Sexagesimal(3, 5, remainder=0.6) # Incorrect parameters with pytest.raises(TypeError): BasedReal() with pytest.raises(ValueError): Sexagesimal(Decimal(5)) with pytest.raises(ValueError): Sexagesimal("", "") with pytest.raises(ValueError): Sexagesimal("", "", "", "") with pytest.raises(TypeError): Sexagesimal(("a", 2), (1, 2)) with pytest.raises(ValueError): Sexagesimal(1, sign=2)
def mul(a: PreciseNumber, b: PreciseNumber): return a._mul(Sexagesimal.from_float(float(b) + 1, 0))
def sub(a: PreciseNumber, b: PreciseNumber): return a._sub(Sexagesimal.from_float(float(b) + 1, 0))
def add(a: PreciseNumber, b: PreciseNumber): return a._add(Sexagesimal.from_float(float(b) + 1, 0))