New test for core tools functions
This commit is contained in:
+15
-5
@@ -141,6 +141,15 @@ def _numberToWordEN(numVal):
|
|||||||
tenWord = ""
|
tenWord = ""
|
||||||
hunWord = ""
|
hunWord = ""
|
||||||
|
|
||||||
|
if not isinstance(numVal, int):
|
||||||
|
return "[NaN]"
|
||||||
|
|
||||||
|
if numVal < 0:
|
||||||
|
return "[Negative]"
|
||||||
|
|
||||||
|
if numVal > 999:
|
||||||
|
return "[Out of Range]"
|
||||||
|
|
||||||
if numVal == 0:
|
if numVal == 0:
|
||||||
return "Zero"
|
return "Zero"
|
||||||
|
|
||||||
@@ -166,19 +175,20 @@ def _numberToWordEN(numVal):
|
|||||||
5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine",
|
5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retVale = ""
|
||||||
hunWord = theHundreds.get(hunVal, "")
|
hunWord = theHundreds.get(hunVal, "")
|
||||||
if tenVal == 10:
|
if tenVal == 10:
|
||||||
oneWord = theTeens.get(oneVal, "")
|
oneWord = theTeens.get(oneVal, "")
|
||||||
return f"{hunWord} {oneWord}".strip()
|
retVale = f"{hunWord} {oneWord}".strip()
|
||||||
else:
|
else:
|
||||||
oneWord = theOnes.get(oneVal, "")
|
oneWord = theOnes.get(oneVal, "")
|
||||||
if tenVal == 0:
|
if tenVal == 0:
|
||||||
return f"{hunWord} {oneWord}".strip()
|
retVale = f"{hunWord} {oneWord}".strip()
|
||||||
else:
|
else:
|
||||||
tenWord = theTens.get(tenVal, "")
|
tenWord = theTens.get(tenVal, "")
|
||||||
if oneVal == 0:
|
if oneVal == 0:
|
||||||
return f"{hunWord} {tenWord}".strip()
|
retVale = f"{hunWord} {tenWord}".strip()
|
||||||
else:
|
else:
|
||||||
return f"{hunWord} {tenWord}-{oneWord}".strip()
|
retVale = f"{hunWord} {tenWord}-{oneWord}".strip()
|
||||||
|
|
||||||
return ""
|
return retVale
|
||||||
|
|||||||
+11
-11
@@ -10,8 +10,8 @@ from nw.core.project import NWProject, NWItem
|
|||||||
from nw.constants import nwItemClass, nwItemType, nwItemLayout
|
from nw.constants import nwItemClass, nwItemType, nwItemLayout
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreItemSetters(dummyGUI):
|
def testCoreItem_Setters(dummyGUI):
|
||||||
"""Test all the simple setter classes for the NWItem class.
|
"""Test all the simple setters for the NWItem class.
|
||||||
"""
|
"""
|
||||||
theProject = NWProject(dummyGUI)
|
theProject = NWProject(dummyGUI)
|
||||||
theItem = NWItem(theProject)
|
theItem = NWItem(theProject)
|
||||||
@@ -144,10 +144,10 @@ def testCoreItemSetters(dummyGUI):
|
|||||||
theItem.saveInitialCount()
|
theItem.saveInitialCount()
|
||||||
assert theItem.initCount == 234
|
assert theItem.initCount == 234
|
||||||
|
|
||||||
# END Test testCoreItemSetters
|
# END Test testCoreItem_Setters
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreItemTypeSetter(dummyGUI):
|
def testCoreItem_TypeSetter(dummyGUI):
|
||||||
"""Test the setter for all the nwItemType values for the NWItem
|
"""Test the setter for all the nwItemType values for the NWItem
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
@@ -172,10 +172,10 @@ def testCoreItemTypeSetter(dummyGUI):
|
|||||||
theItem.setType(nwItemType.ROOT)
|
theItem.setType(nwItemType.ROOT)
|
||||||
assert theItem.itemType == nwItemType.ROOT
|
assert theItem.itemType == nwItemType.ROOT
|
||||||
|
|
||||||
# END Test testCoreItemTypeSetter
|
# END Test testCoreItem_TypeSetter
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreItemClassSetter(dummyGUI):
|
def testCoreItem_ClassSetter(dummyGUI):
|
||||||
"""Test the setter for all the nwItemClass values for the NWItem
|
"""Test the setter for all the nwItemClass values for the NWItem
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
@@ -212,10 +212,10 @@ def testCoreItemClassSetter(dummyGUI):
|
|||||||
theItem.setClass(nwItemClass.NOVEL)
|
theItem.setClass(nwItemClass.NOVEL)
|
||||||
assert theItem.itemClass == nwItemClass.NOVEL
|
assert theItem.itemClass == nwItemClass.NOVEL
|
||||||
|
|
||||||
# END Test testCoreItemClassSetter
|
# END Test testCoreItem_ClassSetter
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreItemLayoutSetter(dummyGUI):
|
def testCoreItem_LayoutSetter(dummyGUI):
|
||||||
"""Test the setter for all the nwItemLayout values for the NWItem
|
"""Test the setter for all the nwItemLayout values for the NWItem
|
||||||
class.
|
class.
|
||||||
"""
|
"""
|
||||||
@@ -248,10 +248,10 @@ def testCoreItemLayoutSetter(dummyGUI):
|
|||||||
theItem.setLayout(nwItemLayout.NOTE)
|
theItem.setLayout(nwItemLayout.NOTE)
|
||||||
assert theItem.itemLayout == nwItemLayout.NOTE
|
assert theItem.itemLayout == nwItemLayout.NOTE
|
||||||
|
|
||||||
# END Test testCoreItemLayoutSetter
|
# END Test testCoreItem_LayoutSetter
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCoreItemXMLPackUnpack(dummyGUI):
|
def testCoreItem_XMLPackUnpack(dummyGUI):
|
||||||
"""Test packing and unpacking XML objects for the NWItem class.
|
"""Test packing and unpacking XML objects for the NWItem class.
|
||||||
"""
|
"""
|
||||||
theProject = NWProject(dummyGUI)
|
theProject = NWProject(dummyGUI)
|
||||||
@@ -379,4 +379,4 @@ def testCoreItemXMLPackUnpack(dummyGUI):
|
|||||||
b"<group/>"
|
b"<group/>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# END Test testCoreItemXMLPackUnpack
|
# END Test testCoreItem_XMLPackUnpack
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import pytest
|
|||||||
from nw.core.tools import countWords, numberToRoman, numberToWord
|
from nw.core.tools import countWords, numberToRoman, numberToWord
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testCountWords():
|
def testCoreTools_CountWords():
|
||||||
"""Test the word counter and the exclusion filers.
|
"""Test the word counter and the exclusion filers.
|
||||||
"""
|
"""
|
||||||
testText = (
|
testText = (
|
||||||
@@ -26,15 +26,46 @@ def testCountWords():
|
|||||||
"\n"
|
"\n"
|
||||||
"\n"
|
"\n"
|
||||||
"The third paragraph.\n"
|
"The third paragraph.\n"
|
||||||
|
"\n"
|
||||||
|
"Dashes\u2013and even longer\u2014dashes."
|
||||||
)
|
)
|
||||||
cC, wC, pC = countWords(testText)
|
cC, wC, pC = countWords(testText)
|
||||||
|
|
||||||
assert cC == 108
|
assert cC == 138
|
||||||
assert wC == 17
|
assert wC == 22
|
||||||
assert pC == 3
|
assert pC == 4
|
||||||
|
|
||||||
|
# END Test testCoreTools_CountWords
|
||||||
|
|
||||||
@pytest.mark.core
|
@pytest.mark.core
|
||||||
def testNumberWords():
|
def testCoreTools_RomanNumbers():
|
||||||
|
"""Test conversion of integers to Roman numbers.
|
||||||
|
"""
|
||||||
|
assert numberToRoman(None, False) == "NAN"
|
||||||
|
assert numberToRoman(0, False) == "OOR"
|
||||||
|
assert numberToRoman(1, False) == "I"
|
||||||
|
assert numberToRoman(2, False) == "II"
|
||||||
|
assert numberToRoman(3, False) == "III"
|
||||||
|
assert numberToRoman(4, False) == "IV"
|
||||||
|
assert numberToRoman(5, False) == "V"
|
||||||
|
assert numberToRoman(6, False) == "VI"
|
||||||
|
assert numberToRoman(7, False) == "VII"
|
||||||
|
assert numberToRoman(8, False) == "VIII"
|
||||||
|
assert numberToRoman(9, False) == "IX"
|
||||||
|
assert numberToRoman(10, False) == "X"
|
||||||
|
assert numberToRoman(14, False) == "XIV"
|
||||||
|
assert numberToRoman(42, False) == "XLII"
|
||||||
|
assert numberToRoman(99, False) == "XCIX"
|
||||||
|
assert numberToRoman(142, False) == "CXLII"
|
||||||
|
assert numberToRoman(542, False) == "DXLII"
|
||||||
|
assert numberToRoman(999, False) == "CMXCIX"
|
||||||
|
assert numberToRoman(2010, False) == "MMX"
|
||||||
|
assert numberToRoman(999, True) == "cmxcix"
|
||||||
|
|
||||||
|
# END Test testCoreTools_RomanNumbers
|
||||||
|
|
||||||
|
@pytest.mark.core
|
||||||
|
def testCoreTools_NumberWords():
|
||||||
"""Test the conversion of integer to English words.
|
"""Test the conversion of integer to English words.
|
||||||
"""
|
"""
|
||||||
assert numberToWord(0, "en") == "Zero"
|
assert numberToWord(0, "en") == "Zero"
|
||||||
@@ -70,27 +101,9 @@ def testNumberWords():
|
|||||||
assert numberToWord(2, "foo") == "Two"
|
assert numberToWord(2, "foo") == "Two"
|
||||||
assert numberToWord(3, "foo") == "Three"
|
assert numberToWord(3, "foo") == "Three"
|
||||||
|
|
||||||
@pytest.mark.core
|
# Test out of range values
|
||||||
def testRomanNumbers():
|
assert numberToWord(12345, "en") == "[Out of Range]"
|
||||||
"""Test conversion of integers to Roman numbers.
|
assert numberToWord(-2345, "en") == "[Negative]"
|
||||||
"""
|
assert numberToWord("234", "en") == "[NaN]"
|
||||||
assert numberToRoman(None, False) == "NAN"
|
|
||||||
assert numberToRoman(0, False) == "OOR"
|
# END Test testCoreTools_NumberWords
|
||||||
assert numberToRoman(1, False) == "I"
|
|
||||||
assert numberToRoman(2, False) == "II"
|
|
||||||
assert numberToRoman(3, False) == "III"
|
|
||||||
assert numberToRoman(4, False) == "IV"
|
|
||||||
assert numberToRoman(5, False) == "V"
|
|
||||||
assert numberToRoman(6, False) == "VI"
|
|
||||||
assert numberToRoman(7, False) == "VII"
|
|
||||||
assert numberToRoman(8, False) == "VIII"
|
|
||||||
assert numberToRoman(9, False) == "IX"
|
|
||||||
assert numberToRoman(10, False) == "X"
|
|
||||||
assert numberToRoman(14, False) == "XIV"
|
|
||||||
assert numberToRoman(42, False) == "XLII"
|
|
||||||
assert numberToRoman(99, False) == "XCIX"
|
|
||||||
assert numberToRoman(142, False) == "CXLII"
|
|
||||||
assert numberToRoman(542, False) == "DXLII"
|
|
||||||
assert numberToRoman(999, False) == "CMXCIX"
|
|
||||||
assert numberToRoman(2010, False) == "MMX"
|
|
||||||
assert numberToRoman(999, True) == "cmxcix"
|
|
||||||
Reference in New Issue
Block a user