Untitled

 avatar
unknown
kotlin
a year ago
5.5 kB
8
Indexable
companion object {
        @JvmStatic
        fun provideTestCases(): Stream<Arguments> {
            return Stream.of(
                Arguments.of(
                    "Killed by bot with gun and have distance",
                    "SCRIPT : string output = '20:35:19.468 [Killfeed] Alema_Gamess got killed by Survivor (Shamans) with AAC Honey Badger from a distance of 33 m.'",
                    notNullValue(), // killedBy
                    notNullValue(), // killedWith
                    notNullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Killed by bot with gun and have distance (different bot group)",
                    "SCRIPT : string output = '18:23:00.476 [Killfeed] LeJack got killed by Survivor (West) with AAC Honey Badger from a distance of 9 m.'",
                    notNullValue(), // killedBy
                    notNullValue(), // killedWith
                    notNullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Simple got killed message",
                    "SCRIPT : string output = '19:02:13.093 [Killfeed] Maggor got killed.'",
                    nullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Simple killed by an something",
                    "SCRIPT : string output = '17:47:57.328 [Killfeed] Maggor got killed by an Infected.'",
                    notNullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Suicide message",
                    "SCRIPT : string output = '03:59:07.288 [Killfeed] MTADOG commited suicide with MK II.'",
                    nullValue(), // killedBy
                    notNullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Beaten to a pulp message",
                    "SCRIPT : string output = '03:55:08.731 [Killfeed] MTADOG got beaten to a pulp by Survivor (Shamans) with bare hands.'",
                    notNullValue(), // killedBy
                    notNullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Starved to death message",
                    "SCRIPT : string output = '20:00:05.851 [Killfeed] SrRa starved to death.'",
                    nullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Burned to death message",
                    "SCRIPT : string output = '14:18:52.664 [Killfeed] SrRa burned to death.'",
                    nullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Bled out message",
                    "SCRIPT : string output = '19:22:56.265 [Killfeed] Pacha bled out.'",
                    nullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Getting mauled by something",
                    "SCRIPT : string output = '20:40:55.125 [Killfeed] Jhonn Skaf got mauled to death by a Wolf.'",
                    notNullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Dehydration message",
                    "SCRIPT : string output = '02:37:51.063 [Killfeed] LeJack died because of dehydration.'",
                    nullValue(), // killedBy
                    nullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                ),
                Arguments.of(
                    "Explosion message",
                    "SCRIPT       : string output = '05:39:22.851 [Killfeed] Ya_Heiro was killed by an explosion caused by 40mm Explosive Grenade.'",
                    notNullValue(), // killedBy
                    notNullValue(), // killedWith
                    nullValue(), // killedDistanceMeters
                )
            )
        }
    }

    @ParameterizedTest(name = "{0}")
    @MethodSource("provideTestCases")
    fun testKillFeedProperInterpretation(
        name: String,
        expression: String,
        killedByMatcher: Matcher<String?>,
        killedWithMatcher: Matcher<String?>,
        killedDistanceMetersMatcher: Matcher<String?>,
    ) {
        println("Testing expression [$expression]")
        val matcher = KillingProcessingEngine.killFeedEventPattern.matcher(expression)
        if (!matcher.find()) {
            assert(false) { "[$expression] doesn't match killfeed pattern" }
            return
        }
        val event = KillFeedEvent(matcher)
        assertThat(event.killedBy, killedByMatcher)
        assertThat(event.killedWith, killedWithMatcher)
        assertThat(event.killedDistanceMeters, killedDistanceMetersMatcher)
    }
Editor is loading...
Leave a Comment