From 937205baa81f5648c728cc39c07c7fe440683237 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 18:06:52 +0200 Subject: [PATCH] add tests for exceptions --- src/MuTalk-Model/MTAnalysis.class.st | 4 ++- src/MuTalk-Tests/MTAnalysisTest.class.st | 33 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index d4ff6a4..6493a33 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -268,7 +268,8 @@ MTAnalysis >> packagesToMutate: aCollectionOfPackages [ MTAnalysis >> percentile: aPercentage for: aCollection [ | size index | - aCollection isEmpty ifTrue: [ ^ nil ]. + aCollection isEmpty ifTrue: [ + ^ CollectionIsEmpty signalWith: aCollection ]. size := aCollection size. index := (aPercentage percent * size) rounded. ^ aCollection at: index @@ -283,6 +284,7 @@ MTAnalysis >> run [ ^ [ self initialTestRun. + "The budget is started after the initial test run because the default one needs the run time of tests" self startBudget. logger logAnalysisStartFor: self. elapsedTime := [ diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index 91f8027..486a923 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -90,6 +90,39 @@ MTAnalysisTest >> testDefaultParameters [ self assert: analysis defaultBudget species equals: MTTimeBudget ] +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenInitializingDefaultTestFilterBeforeInitialTestRun [ + + | analysis | + analysis := MTAnalysis new + classesToMutate: { MTAuxiliarClassForMTAnalysis }; + testClasses: { MTAuxiliarClassForMTAnalysisTest }. + + self should: [ analysis initializeTestFilter ] raise: Error +] + +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenStartingDefaultBudgetBeforeInitialTestRun [ + + | analysis | + analysis := MTAnalysis new + classesToMutate: { MTAuxiliarClassForMTAnalysis }; + testClasses: { MTAuxiliarClassForMTAnalysisTest }. + + self should: [ analysis startBudget ] raise: Error +] + +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenTryingToGetPercentileOfEmptyCollection [ + + | analysis | + analysis := MTAnalysis new. + + self + should: [ analysis percentile: 1 for: { } ] + raise: Error +] + { #category : 'testing' } MTAnalysisTest >> testExecutingInfiniteLoopAnalysis [