From 2019cfa18054e4a98b1ee98aba53c8b4813fa69a Mon Sep 17 00:00:00 2001 From: Sascha Brawer Date: Mon, 8 Jun 2015 17:23:45 +0200 Subject: [PATCH] Move fixedTools tests to unittests Lifted from https://github.com/behdad/fonttools/pull/287 Adds new roundtrip tests, but they are disabled. --- Lib/fontTools/misc/fixedTools.py | 44 --------------------------- Lib/fontTools/misc/fixedTools_test.py | 36 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 Lib/fontTools/misc/fixedTools_test.py diff --git a/Lib/fontTools/misc/fixedTools.py b/Lib/fontTools/misc/fixedTools.py index cd7f38da4..e0cef143b 100644 --- a/Lib/fontTools/misc/fixedTools.py +++ b/Lib/fontTools/misc/fixedTools.py @@ -14,31 +14,7 @@ def fixedToFloat(value, precisionBits): that has the shortest decimal reprentation. Eg. to convert a fixed number in a 2.14 format, use precisionBits=14. This is pretty slow compared to a simple division. Use sporadically. - - >>> "%g" % fixedToFloat(13107, 14) - '0.8' - >>> "%g" % fixedToFloat(0, 14) - '0' - >>> "%g" % fixedToFloat(0x4000, 14) - '1' - >>> "%g" % fixedToFloat(-16384, 14) - '-1' - >>> "%g" % fixedToFloat(-16383, 14) - '-0.99994' - >>> "%g" % fixedToFloat(16384, 14) - '1' - >>> "%g" % fixedToFloat(16383, 14) - '0.99994' - >>> "%g" % fixedToFloat(-639, 6) - '-9.99' - >>> "%g" % fixedToFloat(-640, 6) - '-10' - >>> "%g" % fixedToFloat(639, 6) - '9.99' - >>> "%g" % fixedToFloat(640, 6) - '10' """ - if not value: return 0.0 scale = 1 << precisionBits @@ -66,25 +42,5 @@ def fixedToFloat(value, precisionBits): def floatToFixed(value, precisionBits): """Converts a float to a fixed-point number given the number of precisionBits. Ie. int(round(value * (1<>> floatToFixed(0.8, 14) - 13107 - >>> floatToFixed(1.0, 14) - 16384 - >>> floatToFixed(1, 14) - 16384 - >>> floatToFixed(-1.0, 14) - -16384 - >>> floatToFixed(-1, 14) - -16384 - >>> floatToFixed(0, 14) - 0 """ - return int(round(value * (1<