refining BarChartDescriptionTablesTest
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class BarChartDescriptionTables:
|
class BarChartDescriptionTables:
|
||||||
@@ -24,3 +25,13 @@ class BarChartDescriptionTables:
|
|||||||
def _hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram):
|
def _hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram):
|
||||||
sizeOfGuessedHistogram = sum(barChartDescription['BAR_CHART_DESCRIPTION']['Adverse Reaction Reports guessed'])
|
sizeOfGuessedHistogram = sum(barChartDescription['BAR_CHART_DESCRIPTION']['Adverse Reaction Reports guessed'])
|
||||||
return sizeOfGuessedHistogram >= minSizeOfGuessedHistogram
|
return sizeOfGuessedHistogram >= minSizeOfGuessedHistogram
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def filterHasCountryWithGuessedGreaterThanKnown(barChartDescriptionTable):
|
||||||
|
return barChartDescriptionTable[barChartDescriptionTable.apply(BarChartDescriptionTables._hasCountryWithGuessedGreaterThanKnown, axis='columns')]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _hasCountryWithGuessedGreaterThanKnown(barChartDescription):
|
||||||
|
guessedBarChart = barChartDescription['BAR_CHART_DESCRIPTION']['Adverse Reaction Reports guessed']
|
||||||
|
knownBarChart = barChartDescription['BAR_CHART_DESCRIPTION']['Adverse Reaction Reports known']
|
||||||
|
return np.any(np.asarray(guessedBarChart) > np.asarray(knownBarChart))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from pandas.testing import assert_frame_equal
|
|||||||
from TestHelper import TestHelper
|
from TestHelper import TestHelper
|
||||||
from BarChartDescriptionTables import BarChartDescriptionTables
|
from BarChartDescriptionTables import BarChartDescriptionTables
|
||||||
|
|
||||||
|
|
||||||
class BarChartDescriptionTablesTest(unittest.TestCase):
|
class BarChartDescriptionTablesTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_filterValidJensenShannonDistances(self):
|
def test_filterValidJensenShannonDistances(self):
|
||||||
@@ -37,7 +38,8 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterValidJensenShannonDistances(barChartDescriptionTable)
|
barChartDescriptionTableResult = BarChartDescriptionTables.filterValidJensenShannonDistances(
|
||||||
|
barChartDescriptionTable)
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -82,7 +84,8 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(barChartDescriptionTable, 20)
|
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
||||||
|
barChartDescriptionTable, 20)
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -111,7 +114,8 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(barChartDescriptionTable, 31)
|
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
||||||
|
barChartDescriptionTable, 31)
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -123,3 +127,59 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
[],
|
[],
|
||||||
name='VAX_LOT')),
|
name='VAX_LOT')),
|
||||||
check_dtype=True)
|
check_dtype=True)
|
||||||
|
|
||||||
|
def test_filterHasCountryWithGuessedGreaterThanKnown(self):
|
||||||
|
# Given
|
||||||
|
guessed = 25
|
||||||
|
known = 20
|
||||||
|
barChartDescriptionTable = TestHelper.createDataFrame(
|
||||||
|
columns=['BAR_CHART_DESCRIPTION'],
|
||||||
|
data=[
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'countries': ['Germany', 'Hungary'],
|
||||||
|
'Adverse Reaction Reports guessed': [guessed, 20],
|
||||||
|
'Adverse Reaction Reports known': [known, 30],
|
||||||
|
'Jensen-Shannon distance': 0.4711
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'countries': ['Germany', 'America'],
|
||||||
|
'Adverse Reaction Reports guessed': [25, 20],
|
||||||
|
'Adverse Reaction Reports known': [250, 200],
|
||||||
|
'Jensen-Shannon distance': 0.815
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
index=pd.Index(
|
||||||
|
[
|
||||||
|
'!D0181',
|
||||||
|
'some batch code'
|
||||||
|
],
|
||||||
|
name='VAX_LOT'))
|
||||||
|
|
||||||
|
# When
|
||||||
|
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasCountryWithGuessedGreaterThanKnown(
|
||||||
|
barChartDescriptionTable)
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_frame_equal(
|
||||||
|
barChartDescriptionTableResult,
|
||||||
|
TestHelper.createDataFrame(
|
||||||
|
columns=['BAR_CHART_DESCRIPTION'],
|
||||||
|
data=[
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'countries': ['Germany', 'Hungary'],
|
||||||
|
'Adverse Reaction Reports guessed': [guessed, 20],
|
||||||
|
'Adverse Reaction Reports known': [known, 30],
|
||||||
|
'Jensen-Shannon distance': 0.4711
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
index=pd.Index(
|
||||||
|
[
|
||||||
|
'!D0181'
|
||||||
|
],
|
||||||
|
name='VAX_LOT')),
|
||||||
|
check_dtype=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user