@@ -29,8 +29,6 @@ import type {
2929 StateCoverageItem ,
3030 Trace ,
3131 TraceStep ,
32- TransitionBranchCoverageItem ,
33- TransitionDefinitionCoverageItem ,
3432 VerificationLaw ,
3533 VerificationLawGroup ,
3634 VerificationViolation ,
@@ -41,6 +39,7 @@ import { toArbitraryWithReport } from "./arbitrary.js"
4139import type { FiniteModel } from "./finiteModel.js"
4240import * as ReferenceModel from "./referenceModel.js"
4341import { rawConfigurationPaths , run } from "./trace.js"
42+ import { makeTransitionCoverageCollector , sameTransitionTrigger } from "./transitionCoverage.js"
4443
4544export {
4645 advanceCommand ,
@@ -470,18 +469,6 @@ const normalizeTraces = <M extends AnyMachine>(
470469) : ReadonlyArray < Trace < M > > =>
471470 Array . isArray ( traceOrTraces ) ? traceOrTraces as ReadonlyArray < Trace < M > > : [ traceOrTraces as Trace < M > ]
472471
473- const sameTransitionTrigger = (
474- left : Machine . Machine . TransitionTrigger ,
475- right : Machine . Machine . TransitionTrigger
476- ) : boolean => {
477- if ( left . type !== right . type ) return false
478- if ( left . type === "event" ) return right . type === "event" && left . event === right . event
479- if ( left . type === "invoke" ) {
480- return right . type === "invoke" && left . id === right . id && left . outcome === right . outcome
481- }
482- return true
483- }
484-
485472const targetWithinSelection = (
486473 target : string | undefined ,
487474 branch : Machine . Machine . TransitionBranch ,
@@ -576,48 +563,7 @@ export const coverage = <M extends AnyMachine>(
576563 const entryHits = new Set < number > ( )
577564 const exitHits = new Set < number > ( )
578565
579- const definitions = Machine . transitionDefinitions ( machine ) . map (
580- (
581- definition ,
582- index
583- ) : TransitionDefinitionCoverageItem <
584- StateNodePath < M > ,
585- Machine . Machine . TagOf < Machine . Machine . Events < M > [ number ] > ,
586- StateNodePath < M >
587- > => ( {
588- id : `transition:${ index } ` ,
589- index,
590- source : definition . source ,
591- trigger : definition . trigger ,
592- reenter : definition . reenter ,
593- branches : definition . branches
594- } )
595- )
596- const transitionHits = new Set < number > ( )
597- const branchOffsets : Array < number > = [ ]
598- const branches : Array <
599- TransitionBranchCoverageItem <
600- StateNodePath < M > ,
601- Machine . Machine . TagOf < Machine . Machine . Events < M > [ number ] > ,
602- StateNodePath < M >
603- >
604- > = [ ]
605- for ( let definitionIndex = 0 ; definitionIndex < definitions . length ; definitionIndex ++ ) {
606- branchOffsets . push ( branches . length )
607- const definition = definitions [ definitionIndex ] !
608- definition . branches . forEach ( ( branch , branchIndex ) => {
609- branches . push ( {
610- id : `transition:${ definitionIndex } :branch:${ branchIndex } ` ,
611- definitionIndex,
612- branchIndex,
613- source : definition . source ,
614- trigger : definition . trigger ,
615- reenter : definition . reenter ,
616- branch
617- } )
618- } )
619- }
620- const branchHits = new Set < number > ( )
566+ const transitionCoverage = makeTransitionCoverageCollector ( machine )
621567
622568 const declaredEvents = publicEventTags ( machine )
623569 const declaredEventTags = declaredEvents . tags
@@ -675,6 +621,7 @@ export const coverage = <M extends AnyMachine>(
675621 }
676622
677623 const observeMicrostep = ( microstep : Microstep < M , any > ) : void => {
624+ transitionCoverage . observeMicrostep ( microstep )
678625 microsteps += 1
679626 if ( microstep . changed ) changedMicrosteps += 1
680627 raisedEvents += microstep . raisedEvents . length
@@ -692,20 +639,6 @@ export const coverage = <M extends AnyMachine>(
692639 historyTargets += 1
693640 if ( retained . resolvedTarget !== undefined ) resolvedHistoryTargets += 1
694641 }
695- const definitionIndex = definitions . findIndex ( ( definition ) =>
696- definition . source === retained . source &&
697- definition . reenter === retained . reenter &&
698- sameTransitionTrigger ( definition . trigger , retained . trigger )
699- )
700- if ( definitionIndex === - 1 ) continue
701- transitionHits . add ( definitionIndex )
702- const definition = definitions [ definitionIndex ] !
703- if (
704- Number . isSafeInteger ( retained . branchIndex ) && retained . branchIndex >= 0 &&
705- retained . branchIndex < definition . branches . length
706- ) {
707- branchHits . add ( branchOffsets [ definitionIndex ] ! + retained . branchIndex )
708- }
709642 }
710643 }
711644
@@ -745,10 +678,7 @@ export const coverage = <M extends AnyMachine>(
745678 entry : coverageSummary ( activeNodes , entryHits ) ,
746679 exit : coverageSummary ( activeNodes , exitHits )
747680 } ,
748- transitions : {
749- definitions : coverageSummary ( definitions , transitionHits ) ,
750- branches : coverageSummary ( branches , branchHits )
751- } ,
681+ transitions : transitionCoverage . summary ( ) ,
752682 events : declaredEvents . diagnostics . length === 0
753683 ? {
754684 available : true ,
0 commit comments