def testBlockOfFourIsCompletedCorrectly(self): """Test: Does the last value of a block correctly complete the block itself?""" self.myMainLogic.jsonStore.load_values = lambda id, name: { 'P0': 'A0', 'P1': 'A1', 'P2': 'A2', 'P3': 'A3', 'P4': 'A4', 'P5': 'A5', 'P6': 'A6', 'P7': 'A7', 'P8': 'A8' } self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockOfFourIndexesUncompleteBlock[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValuesUncompleteBlockOfFour[ id] previousValue = None isAlwaysTheSameResult = True for x in range(1000): returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) if previousValue is None: previousValue = returnValue elif previousValue != returnValue: isAlwaysTheSameResult = False break assert (isAlwaysTheSameResult)
def testFirstPatientEver(self): self.myMainLogic.jsonStore.load_values = lambda id, name: {} returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) self.assertEqual(self.resultIndex, self.firstBlockType + str(0)) assert (self.resultIndexInBlock == 4 or self.resultIndexInBlock == 6)
def testPatientIfFirstIndexIsZero(self): self.myMainLogic.jsonStore.load_values = lambda id, name: {'P0': '0'} self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockIndexes[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValues[ id] returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) self.assertEqual(self.resultIndex, 'A0')
def testFirstBlockTypePatientAddedInItsBlockType(self): """Test: Assuming we have mixed blockType, Is the new index considering it block type? Case: secondBlockType""" self.myMainLogic.jsonStore.load_values = lambda id, name: { 'P0': 'A0', 'P1': 'A1', 'P2': 'B0', 'P3': 'A2', 'P4': 'B1' } self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockOfIndexesMixedBlockType[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValuesMixedBlockType[ id] returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.secondBlockType) assert (self.resultIndex == self.secondBlockType + '2')
def testNewBlockWithPreviousBlockOfFourCompleted(self): """Test: Patient is correcly inserted in the second block as first patient of the new block. Testing from block of size four""" self.myMainLogic.jsonStore.load_values = lambda id, name: { 'P0': 'A0', 'P1': 'A1', 'P2': 'A2', 'P3': 'A3' } self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockOfFourIndexesNewBlock[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValuesFromBlockOfFourToNewBlock[ id] returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) self.assertEqual(self.resultIndex, self.firstBlockType + '4') assert (self.resultIndexInBlock == 4 or self.resultIndexInBlock == 6)
def testSelectionIsReallyRandomThirdPatient(self): """ Test: Is third value in a row really random when needed? (one hundred proofs). Case: Third patient in an already balanced block""" self.myMainLogic.jsonStore.load_values = lambda id, name: { 'P0': 'A0', 'P1': 'A1' } self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockIndexes[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValuesRandom[ id] valueList = [] for x in range(1000): returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) valueList.append(returnValue) print valueList.count(False) print valueList.count(True) assert (valueList and len(list(set(valueList))) > 1)
def testBlockOfFourWithPreviousBlockCompleted(self): """Test: Patient is correcly inserted in the second block (already started). Testing block of size four""" self.myMainLogic.jsonStore.load_values = lambda id, name: { 'P0': 'A0', 'P1': 'A1', 'P2': 'A2', 'P3': 'A3', 'P4': 'A4', 'P5': 'A5', 'P6': 'A6', 'P7': 'A7', 'P8': 'A8' } self.myMainLogic.jsonStore.load_value = lambda id, name: self.listOfBlockOfFourIndexesUncompleteBlock[ id ] if name == 'crfs.' + self.indexInBlockAttributeName else self.listOfRandomizationValuesUncompleteBlockOfFour[ id] returnValue = psevaluator.randomBlocksRandomization( self.indexAttributeName, self.indexInBlockAttributeName, self.randomizationResultAttributeName, self.randomizationResultStudy, self.randomizationResultControl, self.firstBlockType) self.assertEqual(self.resultIndex, self.firstBlockType + '9') assert (self.resultIndexInBlock == 1)