refining BarChartDescriptionTablesTest
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import math
|
||||
import numpy as np
|
||||
|
||||
|
||||
class BarChartDescriptionTables:
|
||||
@@ -24,3 +25,13 @@ class BarChartDescriptionTables:
|
||||
def _hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram):
|
||||
sizeOfGuessedHistogram = sum(barChartDescription['BAR_CHART_DESCRIPTION']['Adverse Reaction Reports guessed'])
|
||||
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,121 +5,181 @@ from pandas.testing import assert_frame_equal
|
||||
from TestHelper import TestHelper
|
||||
from BarChartDescriptionTables import BarChartDescriptionTables
|
||||
|
||||
|
||||
class BarChartDescriptionTablesTest(unittest.TestCase):
|
||||
|
||||
def test_filterValidJensenShannonDistances(self):
|
||||
# Given
|
||||
barChartDescriptionTable = TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [0, 0],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': np.nan
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'countries': ['Germany'],
|
||||
'Adverse Reaction Reports guessed': [70],
|
||||
'Adverse Reaction Reports known': [80],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
[
|
||||
'!D0181',
|
||||
'# 009C01A'
|
||||
],
|
||||
name = 'VAX_LOT'))
|
||||
columns=['BAR_CHART_DESCRIPTION'],
|
||||
data=[
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [0, 0],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': np.nan
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
'countries': ['Germany'],
|
||||
'Adverse Reaction Reports guessed': [70],
|
||||
'Adverse Reaction Reports known': [80],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index=pd.Index(
|
||||
[
|
||||
'!D0181',
|
||||
'# 009C01A'
|
||||
],
|
||||
name='VAX_LOT'))
|
||||
|
||||
# When
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterValidJensenShannonDistances(barChartDescriptionTable)
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterValidJensenShannonDistances(
|
||||
barChartDescriptionTable)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
barChartDescriptionTableResult,
|
||||
TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [
|
||||
[
|
||||
{
|
||||
'countries': ['Germany'],
|
||||
'Adverse Reaction Reports guessed': [70],
|
||||
'Adverse Reaction Reports known': [80],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
columns=['BAR_CHART_DESCRIPTION'],
|
||||
data=[
|
||||
[
|
||||
{
|
||||
'countries': ['Germany'],
|
||||
'Adverse Reaction Reports guessed': [70],
|
||||
'Adverse Reaction Reports known': [80],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index=pd.Index(
|
||||
[
|
||||
'# 009C01A',
|
||||
],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
name='VAX_LOT')),
|
||||
check_dtype=True)
|
||||
|
||||
def test_filterHasMinSizeOfGuessedHistogram_true(self):
|
||||
# Given
|
||||
barChartDescriptionTable = TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [10, 20],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
[
|
||||
'!D0181'
|
||||
],
|
||||
name = 'VAX_LOT'))
|
||||
columns=['BAR_CHART_DESCRIPTION'],
|
||||
data=[
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [10, 20],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index=pd.Index(
|
||||
[
|
||||
'!D0181'
|
||||
],
|
||||
name='VAX_LOT'))
|
||||
|
||||
# When
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(barChartDescriptionTable, 20)
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
||||
barChartDescriptionTable, 20)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
barChartDescriptionTableResult,
|
||||
barChartDescriptionTable,
|
||||
check_dtype = True)
|
||||
check_dtype=True)
|
||||
|
||||
def test_filterHasMinSizeOfGuessedHistogram_false(self):
|
||||
# Given
|
||||
barChartDescriptionTable = TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [10, 20],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
[
|
||||
'!D0181'
|
||||
],
|
||||
name = 'VAX_LOT'))
|
||||
columns=['BAR_CHART_DESCRIPTION'],
|
||||
data=[
|
||||
[
|
||||
{
|
||||
'countries': ['Germany', 'Hungary'],
|
||||
'Adverse Reaction Reports guessed': [10, 20],
|
||||
'Adverse Reaction Reports known': [20, 30],
|
||||
'Jensen-Shannon distance': 0.4711
|
||||
}
|
||||
]
|
||||
],
|
||||
index=pd.Index(
|
||||
[
|
||||
'!D0181'
|
||||
],
|
||||
name='VAX_LOT'))
|
||||
|
||||
# When
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(barChartDescriptionTable, 31)
|
||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
||||
barChartDescriptionTable, 31)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
barChartDescriptionTableResult,
|
||||
TestHelper.createDataFrame(
|
||||
columns = ['BAR_CHART_DESCRIPTION'],
|
||||
data = [],
|
||||
index = pd.Index(
|
||||
columns=['BAR_CHART_DESCRIPTION'],
|
||||
data=[],
|
||||
index=pd.Index(
|
||||
[],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
name='VAX_LOT')),
|
||||
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