From ab37d228eaac3bdc1106abb6427e209b5f95692b Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Fri, 8 Nov 2019 08:34:22 +0200 Subject: [PATCH 1/2] Added central place to get damage types and ehp sources. Added tests --- eos/utils/stats.py | 46 ++++++++++++---- .../test_eos/test_utils/test_stats.py | 53 +++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 tests/test_modules/test_eos/test_utils/test_stats.py diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 95f13aa95..8fd778c56 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -46,11 +46,11 @@ class DmgTypes: # Round for comparison's sake because often damage profiles are # generated from data which includes float errors return ( - floatUnerr(self.em) == floatUnerr(other.em) and - floatUnerr(self.thermal) == floatUnerr(other.thermal) and - floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and - floatUnerr(self.explosive) == floatUnerr(other.explosive) and - floatUnerr(self.total) == floatUnerr(other.total)) + floatUnerr(self.em) == floatUnerr(other.em) and + floatUnerr(self.thermal) == floatUnerr(other.thermal) and + floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and + floatUnerr(self.explosive) == floatUnerr(other.explosive) and + floatUnerr(self.total) == floatUnerr(other.total)) def __bool__(self): return any(( @@ -110,9 +110,20 @@ class DmgTypes: return self def __repr__(self): - spec = ['em', 'thermal', 'kinetic', 'explosive', 'total'] + spec = DmgTypes.Names() + spec.append('total') return makeReprStr(self, spec) + @staticmethod + def Names(short=None, postProcessor=None): + value = ['em', 'th', 'kin', 'exp'] if short else ['em', 'thermal', 'kinetic', 'explosive'] + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value + class RRTypes: """Container for tank data stats.""" @@ -136,10 +147,10 @@ class RRTypes: # Round for comparison's sake because often tanking numbers are # generated from data which includes float errors return ( - floatUnerr(self.shield) == floatUnerr(other.shield) and - floatUnerr(self.armor) == floatUnerr(other.armor) and - floatUnerr(self.hull) == floatUnerr(other.hull) and - floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) + floatUnerr(self.shield) == floatUnerr(other.shield) and + floatUnerr(self.armor) == floatUnerr(other.armor) and + floatUnerr(self.hull) == floatUnerr(other.hull) and + floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) def __bool__(self): return any((self.shield, self.armor, self.hull, self.capacitor)) @@ -191,5 +202,18 @@ class RRTypes: return self def __repr__(self): - spec = ['shield', 'armor', 'hull', 'capacitor'] + spec = RRTypes.Names(False) return makeReprStr(self, spec) + + @staticmethod + def Names(ehpOnly=True, postProcessor=None): + value = ['shield', 'armor', 'hull'] + + if not ehpOnly: + value.append('capacitor') + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value diff --git a/tests/test_modules/test_eos/test_utils/test_stats.py b/tests/test_modules/test_eos/test_utils/test_stats.py new file mode 100644 index 000000000..043f53a7f --- /dev/null +++ b/tests/test_modules/test_eos/test_utils/test_stats.py @@ -0,0 +1,53 @@ +# Add root folder to python paths +# This must be done on every test in order to pass in Travis +import os +import sys + +script_dir = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..', '..', '..'))) + +import pytest +from eos.utils.stats import DmgTypes, RRTypes + + +@pytest.fixture() +def setup_damage_types(): + return DmgTypes(10, 20, 30, 40) + + +def test_dmgtypes_names(): + assert DmgTypes.Names() == ['em', 'thermal', 'kinetic', 'explosive'] + assert DmgTypes.Names(True) == ['em', 'th', 'kin', 'exp'] + assert DmgTypes.Names(short=True) == ['em', 'th', 'kin', 'exp'] + + +def test_dmgtypes__repr(setup_damage_types): + assert setup_damage_types.__repr__() == '' + + +def test_dmgtypes_names_lambda(): + assert DmgTypes.Names(False, lambda v: v.capitalize()) == ['Em', 'Thermal', 'Kinetic', 'Explosive'] + assert DmgTypes.Names(True, lambda v: v.upper()) == ['EM', 'TH', 'KIN', 'EXP'] + + +@pytest.fixture() +def setup_rr_types(): + return RRTypes(10, 20, 30, 40) + + +def test_rrtypes_names(): + assert RRTypes.Names() == ['shield', 'armor', 'hull'] + assert RRTypes.Names(True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(ehpOnly=True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(False) == ['shield', 'armor', 'hull', 'capacitor'] + + +def test_rrtypes__repr(setup_rr_types): + assert setup_rr_types.__repr__() == '' + + +def test_rrtypes_names_lambda(): + assert RRTypes.Names(True, lambda v: v.capitalize()) == ['Shield', 'Armor', 'Hull'] + assert RRTypes.Names(postProcessor=lambda v: v.upper(), ehpOnly=False) == ['SHIELD', 'ARMOR', 'HULL', 'CAPACITOR'] + + From 1975e96848b2141008ad9da7c4e289a42219c5da Mon Sep 17 00:00:00 2001 From: Gochim <54093496+Gochim@users.noreply.github.com> Date: Fri, 8 Nov 2019 08:34:22 +0200 Subject: [PATCH 2/2] Added central place to get damage types and ehp sources. Added tests --- eos/utils/stats.py | 46 ++++++++++++---- .../test_eos/test_utils/test_stats.py | 53 +++++++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 tests/test_modules/test_eos/test_utils/test_stats.py diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 95f13aa95..8fd778c56 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -46,11 +46,11 @@ class DmgTypes: # Round for comparison's sake because often damage profiles are # generated from data which includes float errors return ( - floatUnerr(self.em) == floatUnerr(other.em) and - floatUnerr(self.thermal) == floatUnerr(other.thermal) and - floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and - floatUnerr(self.explosive) == floatUnerr(other.explosive) and - floatUnerr(self.total) == floatUnerr(other.total)) + floatUnerr(self.em) == floatUnerr(other.em) and + floatUnerr(self.thermal) == floatUnerr(other.thermal) and + floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and + floatUnerr(self.explosive) == floatUnerr(other.explosive) and + floatUnerr(self.total) == floatUnerr(other.total)) def __bool__(self): return any(( @@ -110,9 +110,20 @@ class DmgTypes: return self def __repr__(self): - spec = ['em', 'thermal', 'kinetic', 'explosive', 'total'] + spec = DmgTypes.Names() + spec.append('total') return makeReprStr(self, spec) + @staticmethod + def Names(short=None, postProcessor=None): + value = ['em', 'th', 'kin', 'exp'] if short else ['em', 'thermal', 'kinetic', 'explosive'] + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value + class RRTypes: """Container for tank data stats.""" @@ -136,10 +147,10 @@ class RRTypes: # Round for comparison's sake because often tanking numbers are # generated from data which includes float errors return ( - floatUnerr(self.shield) == floatUnerr(other.shield) and - floatUnerr(self.armor) == floatUnerr(other.armor) and - floatUnerr(self.hull) == floatUnerr(other.hull) and - floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) + floatUnerr(self.shield) == floatUnerr(other.shield) and + floatUnerr(self.armor) == floatUnerr(other.armor) and + floatUnerr(self.hull) == floatUnerr(other.hull) and + floatUnerr(self.capacitor) == floatUnerr(other.capacitor)) def __bool__(self): return any((self.shield, self.armor, self.hull, self.capacitor)) @@ -191,5 +202,18 @@ class RRTypes: return self def __repr__(self): - spec = ['shield', 'armor', 'hull', 'capacitor'] + spec = RRTypes.Names(False) return makeReprStr(self, spec) + + @staticmethod + def Names(ehpOnly=True, postProcessor=None): + value = ['shield', 'armor', 'hull'] + + if not ehpOnly: + value.append('capacitor') + + if postProcessor: + value = [postProcessor(x) for x in value] + print(value) + + return value diff --git a/tests/test_modules/test_eos/test_utils/test_stats.py b/tests/test_modules/test_eos/test_utils/test_stats.py new file mode 100644 index 000000000..043f53a7f --- /dev/null +++ b/tests/test_modules/test_eos/test_utils/test_stats.py @@ -0,0 +1,53 @@ +# Add root folder to python paths +# This must be done on every test in order to pass in Travis +import os +import sys + +script_dir = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.realpath(os.path.join(script_dir, '..', '..', '..', '..'))) + +import pytest +from eos.utils.stats import DmgTypes, RRTypes + + +@pytest.fixture() +def setup_damage_types(): + return DmgTypes(10, 20, 30, 40) + + +def test_dmgtypes_names(): + assert DmgTypes.Names() == ['em', 'thermal', 'kinetic', 'explosive'] + assert DmgTypes.Names(True) == ['em', 'th', 'kin', 'exp'] + assert DmgTypes.Names(short=True) == ['em', 'th', 'kin', 'exp'] + + +def test_dmgtypes__repr(setup_damage_types): + assert setup_damage_types.__repr__() == '' + + +def test_dmgtypes_names_lambda(): + assert DmgTypes.Names(False, lambda v: v.capitalize()) == ['Em', 'Thermal', 'Kinetic', 'Explosive'] + assert DmgTypes.Names(True, lambda v: v.upper()) == ['EM', 'TH', 'KIN', 'EXP'] + + +@pytest.fixture() +def setup_rr_types(): + return RRTypes(10, 20, 30, 40) + + +def test_rrtypes_names(): + assert RRTypes.Names() == ['shield', 'armor', 'hull'] + assert RRTypes.Names(True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(ehpOnly=True) == ['shield', 'armor', 'hull'] + assert RRTypes.Names(False) == ['shield', 'armor', 'hull', 'capacitor'] + + +def test_rrtypes__repr(setup_rr_types): + assert setup_rr_types.__repr__() == '' + + +def test_rrtypes_names_lambda(): + assert RRTypes.Names(True, lambda v: v.capitalize()) == ['Shield', 'Armor', 'Hull'] + assert RRTypes.Names(postProcessor=lambda v: v.upper(), ehpOnly=False) == ['SHIELD', 'ARMOR', 'HULL', 'CAPACITOR'] + +