Skip to content

Commit 8821081

Browse files
committed
cover more cases
1 parent 5f82304 commit 8821081

File tree

2 files changed

+157
-6
lines changed

2 files changed

+157
-6
lines changed

test_case/hello.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,55 @@ export class DistanceBasedDeliveryStrategy implements EmissionStrategy {
2424
void emissionGroup;
2525
return true;
2626
}
27-
determineCooldown(emissionGroup: EmissionGroup): DelayType {
28-
void emissionGroup;
29-
return this.context.getCurrentZone().isPresent() &&
30-
this.context.getCurrentZone().get() === ZoneType.RESIDENTIAL
31-
? DelayType.SHORT
32-
: DelayType.NEVER;
27+
28+
private checkStateChange(attr: NumericProperty): bool {
29+
return (
30+
attr.getCurrent().isUnstable() &&
31+
attr.getPrevious() != null &&
32+
attr.getPrevious()!.isStable()
33+
);
34+
}
35+
36+
public isEqual(other: GenericValueContainer<i32>): bool {
37+
return (
38+
this.isStable() == other.isStable() &&
39+
this.isActive() == other.isActive() &&
40+
(!this.isActive() || this.getValue() == other.getValue())
41+
);
3342
}
43+
44+
public copy(): GenericValueContainer<i64> {
45+
const clone = new LongValueWrapper(this.initializer);
46+
clone.status = this.status;
47+
clone.error = this.error;
48+
return clone;
49+
}
50+
}
51+
52+
let activeConfig: BaseConfiguration;
53+
const configData = AppContext.loadSettings();
54+
55+
if (configData) {
56+
activeConfig = configData;
57+
} else {
58+
activeConfig = new BaseConfiguration();
59+
activeConfig.initializationDelay = Constants.DEFAULT_INIT_DELAY;
60+
activeConfig.fastPollingInterval = Constants.DEFAULT_FAST_INTERVAL;
61+
activeConfig.normalPollingInterval = Constants.DEFAULT_NORMAL_INTERVAL;
62+
}
63+
64+
if (runtimeEnv && eventController) {
65+
SystemHookManager.instance = this;
66+
this.eventController = eventController;
67+
runtimeEnv.registerStateChangeListener(SystemHookManager.handleStateChange);
68+
this.lastKnownState = runtimeEnv.getCurrentEnvironmentState();
69+
}
70+
71+
if (
72+
currentSession.authType == AuthType.PRIVILEGED &&
73+
currentSession.status == SessionStatus.ACTIVE &&
74+
this.runtimeEnv.getCurrentEnvironmentState().isPresent()
75+
) {
76+
const timestamp = getTimestamp();
77+
serviceInstance.lastSyncTime = timestamp;
3478
}

tests/perf-plugin.test.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,99 @@ RuleTester.itOnly = test.it.only;
1010

1111
const ruleTester = new RuleTester();
1212

13+
14+
ruleTester.run(
15+
"no-repeated-member-access",
16+
perfPlugin.rules["no-repeated-member-access"],
17+
{
18+
valid: [`
19+
import { DelayType } from "@utils/time-utils";
20+
21+
export namespace TimingConfig {
22+
export const defaultCooldownStandard: u32 = DelayType.STANDARD;
23+
/**
24+
* Cooldown duration for urban positioning scenarios
25+
*/
26+
export const urbanPositioningCooldown = DelayType.SHORT;
27+
/**
28+
* Cooldown duration for high-speed positioning scenarios
29+
*/
30+
export const highSpeedPositioningCooldown = DelayType.LONG;
31+
}
32+
33+
/**
34+
* Distance-based emission strategy
35+
*/
36+
export class DistanceBasedDeliveryStrategy implements EmissionStrategy {
37+
private context: SystemContext;
38+
constructor(context: SystemContext) {
39+
this.context = context;
40+
}
41+
isEmissionConditionMet(emissionGroup: EmissionGroup): boolean {
42+
void emissionGroup;
43+
return true;
44+
}
45+
46+
private checkStateChange(attr: NumericProperty): bool {
47+
return (
48+
attr.getCurrent().isUnstable() &&
49+
attr.getPrevious() != null &&
50+
attr.getPrevious()!.isStable()
51+
);
52+
}
53+
54+
public isEqual(other: GenericValueContainer<i32>): bool {
55+
return (
56+
this.isStable() == other.isStable() &&
57+
this.isActive() == other.isActive() &&
58+
(!this.isActive() || this.getValue() == other.getValue())
59+
);
60+
}
61+
62+
public copy(): GenericValueContainer<i64> {
63+
const clone = new LongValueWrapper(this.initializer);
64+
clone.status = this.status;
65+
clone.error = this.error;
66+
return clone;
67+
}
68+
}
69+
70+
let activeConfig: BaseConfiguration;
71+
const configData = AppContext.loadSettings();
72+
73+
if (configData) {
74+
activeConfig = configData;
75+
} else {
76+
activeConfig = new BaseConfiguration();
77+
activeConfig.initializationDelay = Constants.DEFAULT_INIT_DELAY;
78+
activeConfig.fastPollingInterval = Constants.DEFAULT_FAST_INTERVAL;
79+
activeConfig.normalPollingInterval = Constants.DEFAULT_NORMAL_INTERVAL;
80+
}
81+
82+
if (runtimeEnv && eventController) {
83+
SystemHookManager.instance = this;
84+
this.eventController = eventController;
85+
runtimeEnv.registerStateChangeListener(SystemHookManager.handleStateChange);
86+
this.lastKnownState = runtimeEnv.getCurrentEnvironmentState();
87+
}
88+
89+
if (
90+
currentSession.authType == AuthType.PRIVILEGED &&
91+
currentSession.status == SessionStatus.ACTIVE &&
92+
this.runtimeEnv.getCurrentEnvironmentState().isPresent()
93+
) {
94+
const timestamp = getTimestamp();
95+
serviceInstance.lastSyncTime = timestamp;
96+
}
97+
98+
`],
99+
100+
invalid: [
101+
],
102+
}
103+
);
104+
105+
/*
13106
// Throws error if the tests in ruleTester.run() do not pass
14107
ruleTester.run(
15108
"array-init-style", // rule name
@@ -78,6 +171,19 @@ ruleTester.run(
78171
}
79172
}
80173
`,
174+
`
175+
import { Juice } from "@applejuice"
176+
export const apple = Juice.D31
177+
export const banana = Juice.D32
178+
export const cat = Juice.D33
179+
`,
180+
`
181+
export namespace Constants {
182+
export const defaultDebounceTimeRegular_s: u32 = SendTime.NEXT_REGULAR
183+
export const debounceTimeGnssInnerCity_s = SendTime.S30
184+
export const debounceTimeGnssMotorway_s = SendTime.S120
185+
}
186+
`,
81187
],
82188
83189
invalid: [
@@ -190,3 +296,4 @@ const v1 = _ctx_data.v1;
190296
],
191297
}
192298
);
299+
*/

0 commit comments

Comments
 (0)