• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-js / 12431963409

20 Dec 2024 01:05PM CUT coverage: 84.624% (-0.001%) from 84.625%
12431963409

Pull #4823

github

web-flow
Merge 04876b140 into 3b8fcab21
Pull Request #4823: fix: [#4684] ESLint issues in botbuilder-testing

8185 of 10821 branches covered (75.64%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 1 file covered. (100.0%)

20512 of 23090 relevant lines covered (88.83%)

7391.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

13.79
/libraries/botbuilder-dialogs-adaptive/src/entityAssignmentComparer.ts
1
/**
2
 * @module adaptive-expressions
3
 */
4
/**
5
 * Copyright (c) Microsoft Corporation. All rights reserved.
6
 * Licensed under the MIT License.
7
 */
8
import { AdaptiveEvents } from './adaptiveEvents';
2✔
9
import { EntityAssignment } from './entityAssignment';
10

11
/**
12
 * Compare two entity assignments to determine their relative priority.
13
 *
14
 * @remarks
15
 * Compare by event: assignEntity, chooseProperty, chooseEntity
16
 * Then by operations in order from schema (usually within assignEntity).
17
 * Then by unexpected before expected.
18
 * Then by oldest turn first.
19
 * Then by minimum position in utterance.
20
 */
21
export class EntityAssignmentComparer {
2✔
22
    private static eventPreference = [
2✔
23
        AdaptiveEvents.assignEntity,
24
        AdaptiveEvents.chooseProperty,
25
        AdaptiveEvents.chooseEntity,
26
    ];
27

28
    /**
29
     * Initializes a new instance of the [EntityAssignmentComparer](xref:botbuilder-dialogs-adaptive.EntityAssignmentComparer) class.
30
     *
31
     * @param operationPreference Preference on operations.
32
     */
33
    constructor(private operationPreference: string[]) {}
8✔
34

35
    /**
36
     * Compares [EntityAssignment](xref:botbuilder-dialogs-adaptive.EntityAssignment) x against y to determine its relative priority.
37
     *
38
     * @param x First entity assigment to compare.
39
     * @param y Second entity assigment to compare.
40
     * @returns Numerical value representing x's relative priority.
41
     */
42
    compare(x: Partial<EntityAssignment>, y: Partial<EntityAssignment>): number {
43
        // Order by event.
44
        let comparison: number =
45
            EntityAssignmentComparer.eventPreference.indexOf(x.event) -
×
46
            EntityAssignmentComparer.eventPreference.indexOf(y.event);
47
        if (comparison === 0) {
×
48
            // Order by operations.
49
            comparison = this.operationPreference.indexOf(x.operation) - this.operationPreference.indexOf(y.operation);
×
50
            if (comparison === 0) {
×
51
                // Unexpected before expected.
52
                if (x.isExpected === y.isExpected) {
×
53
                    comparison = 0;
×
54
                } else {
55
                    comparison = x.isExpected ? -1 : 1;
×
56
                }
57

58
                if (comparison === 0) {
×
59
                    // Order by position in utterance.
60
                    comparison = x.value?.start - y.value?.start;
×
61
                }
62
            }
63
        }
64

65
        return comparison;
×
66
    }
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc