Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • selsky/ntpsec
  • armbiant/gnome-ntpsec
  • smallm/ntpsec
  • devicenull/ntpsec
  • paelzer/ntpsec
  • mvangund/ntpsec
  • fe051/ntpsec
  • ollie314/ntpsec
  • rlaager/ntpsec
  • fhgwright/ntpsec
  • phirephly/ntpsec
  • Omnifarious/ntpsec
  • ghane/ntpsec
  • antranigv/ntpsec
  • pakarsolusitelematika/ntpsec
  • ianbruene/ntpsec
  • wingel/ntpsec
  • katyaBeck/ntpsec
  • akumiszcza/ntpsec
  • rouing/ntpsec
  • NTPsec/ntpsec
  • mlichvar/ntpsec
  • ktims/ntpsec
  • fararano.kevin/ntpsec
  • phillipcharleshart/ntpsec
  • SPACE001/ntpsec
  • thomasdstewart/ntpsec
  • testsleeek/ntpsec
  • NeatNerdPrime/ntpsec
  • marcinbrodowski35/ntpsec
  • AbbasDev/ntpsec
  • jurgen.xhelo/ntpsec
  • Wan10/ntpsec
  • BrnoPCmaniak/ntpsec
  • anastrophe/ntpsec
  • georgyo/ntpsec
  • mikie.simpson/ntpsec
  • OptimalRanging/ntpsec
  • toofishes/ntpsec
  • Jandrusk/ntpsec
  • sdwalker/ntpsec
  • mnordhoff/ntpsec
  • cjmayo/ntpsec
  • micromax/ntpsec
  • tychotithonus/ntpsec
  • ddrown/ntpsec
  • brendanbank/ntpsec
  • jh23453/ntpsec
  • samifarin/ntpsec
  • miller24joseph/ntpsec
  • AZDNice/ntpsec
  • lnceballos/ntpsec
  • gabriel-ku/ntpsec
  • psreport/ntpsec
  • thesamesam/ntpsec
  • alexk7/ntpsec
  • RRZEFox/ntpsec
  • m_by/ntpsec
  • jameshilliard/ntpsec
  • daemoneye/ntpsec
  • xgerault/ntpsec
  • permanent-vacations/ntpsec
  • o.zeynalpour/ntpsec
  • ravi.love.nippy/ntpsec
  • jhamlin96/ntpsec
  • abaehr/ntpsec
  • accidentallythecable-public/forks/ntpsec
  • james.jstroud/ntpsec
  • youwt19821020/ntpsec-no-root
  • jamesb_fe80/ntpsec
  • demsjf8/ntpsec
  • yegorich/ntpsec
  • 1963bib/ntpsec
  • armbiant/gnome-ntp
  • chucalu/ntpsec
  • folkertvanheusden/ntpsec
  • mktyler/ntpsec
  • 19bcs2794/ntpsec
  • LOCNNIL/ntpsec
  • lifeofguenter/ntpsec
  • trv-n/ntpsec-trimble-3
  • szepeviktor/ntpsec
  • lightswitch05/ntpsec
  • m_msft/ntpsec
84 results
Show changes
Commits on Source (2)
......@@ -181,6 +181,34 @@ def oomsbetweenunits(a, b):
return abs((a - b) * 3)
def breaknumberstring(value):
"Breaks a number string into (aboveDecimal, belowDecimal, isNegative?)"
if value[0] == "-":
value = value[1:]
negative = True
else:
negative = False
if "." in value:
above, below = value.split(".")
else:
above = value
below = ""
return (above, below, negative)
def gluenumberstring(above, below, isnegative):
"Glues together parts of a number string"
if above == "":
above = "0"
if len(below) > 0:
newvalue = ".".join((above, below))
else:
newvalue = above
if isnegative is True:
newvalue = "-" + newvalue
return newvalue
def rescalestring(value, unitsscaled):
"Rescale a number string by a given number of units"
if unitsscaled == 0:
......
......@@ -211,5 +211,38 @@ class TestPylibUtilMethods(unittest.TestCase):
# ditto, negative
self.assertEqual(f("-1.23456", -2), "-1234560")
def test_breaknumberstring(self):
f = ntp.util.breaknumberstring
# No decimals, positive
self.assertEqual(f("1234567890"), ("1234567890", "", False))
# ditto, negative
self.assertEqual(f("-1234567890"), ("1234567890", "", True))
# No whole, positive
self.assertEqual(f(".12345"), ("", "12345", False))
# ditto, negative
self.assertEqual(f("-.12345"), ("", "12345", True))
# Both sides, position
self.assertEqual(f("123.456"), ("123", "456", False))
# ditto, negative
self.assertEqual(f("-123.456"), ("123", "456", True))
def test_gluenumberstring(self):
f = ntp.util.gluenumberstring
# No decimals, positive
self.assertEqual(f("123", "", False), "123")
# ditto, negative
self.assertEqual(f("123", "", True), "-123")
# No whole, positive
self.assertEqual(f("", "456", False), "0.456")
# ditto, negative
self.assertEqual(f("", "456", True), "-0.456")
# Both sides, positive
self.assertEqual(f("123", "456", False), "123.456")
# ditto, negative
self.assertEqual(f("123", "456", True), "-123.456")
if __name__ == '__main__':
unittest.main()