def test_csd1(): """[summary] """ csdstr = "+00-00+" csdnumber = to_decimal(csdstr) csdnew = to_csd(csdnumber) assert csdnew == csdstr
def test__01_to_decimal(self): """ Check the conversion from CSD with a binary point to decimal. """ for key in good_values_dict.keys(): csd_str = good_values_dict[key] value = csd.to_decimal(csd_str) self.assertEqual(value, key)
def test_csd4(): """[summary] """ n = 545 csdstr = to_csd(n) n2 = to_decimal(csdstr) assert n == n2
def test_csd3(): """[summary] """ csdstr = "+00-.000+" csdnumber = to_decimal(csdstr) csdnew = to_csdfixed(csdnumber, nnz=3) assert csdnew == csdstr
def test_csd2(): """[summary] """ csdstr = "+00-.000+" csdnumber = to_decimal(csdstr) csdnew = to_csd(csdnumber, places=4) assert csdnew == csdstr
def __call__(self, r: Arr, Spsq, retry: bool): """[summary] Arguments: r (Arr): [description] Spsq ([type]): [description] retry (int): [description] Returns: [type]: [description] """ if not retry: # retry due to no effect in the previous cut self.lowpass.retry = False cut, Spsq2 = self.lowpass(r, Spsq) if Spsq2 is None: # infeasible return cut, r, None, True h = spectral_fact(r) hcsd = np.array( [to_decimal(to_csdfixed(hi, self.nnz)) for hi in h]) self.rcsd = inverse_spectral_fact(hcsd) (gc, hc), Spsq2 = self.lowpass(self.rcsd, Spsq) # no more alternative cuts? hc += gc @ (self.rcsd - r) more_alt = self.lowpass.more_alt and not retry return (gc, hc), self.rcsd, Spsq2, more_alt
def cycle_bits(i): global indent_ indent_ += 2 for ch in ('0', '-', '+'): csd_num[i] = ch if (i > 0): cycle_bits(i - 1) else: if is_proper_csd(csd_num): csd_str = ''.join(csd_num) num = csd.to_decimal(csd_str) csd_dict[num] = csd_str indent_ -= 2
def test__01a_to_decimal(self): self.assertEqual(csd.to_decimal('0.+00-'), 0.5 - (2.0**-4)) self.assertEqual(csd.to_decimal('0.0+0-'), 0.25 - (2.0**-4)) self.assertEqual(csd.to_decimal('0.+0-0'), 0.5 - (2.0**-3))