All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rapatao.projects.ruleset.engine.cases.MatcherCases.kt Maven / Gradle / Ivy

Go to download

Simple yet powerful rules engine that offers the flexibility of using the built-in engine and creating a custom one.

The newest version!
package com.rapatao.projects.ruleset.engine.cases

import com.rapatao.projects.ruleset.engine.types.builder.MatcherBuilder.allMatch
import com.rapatao.projects.ruleset.engine.types.builder.MatcherBuilder.anyMatch
import com.rapatao.projects.ruleset.engine.types.builder.MatcherBuilder.noneMatch
import com.rapatao.projects.ruleset.engine.types.builder.extensions.expContains
import com.rapatao.projects.ruleset.engine.types.builder.extensions.greaterOrEqualThan
import com.rapatao.projects.ruleset.engine.types.builder.extensions.lessOrEqualThan
import org.junit.jupiter.params.provider.Arguments

object MatcherCases {

    fun cases(): List = noneMatchCases() + allMatchCases() + anyMatchCases()

    @Suppress("LongMethod")
    private fun noneMatchCases(): List = listOf(
        Arguments.of(
            noneMatch("item.price" greaterOrEqualThan "1000"),
            true
        ),
        Arguments.of(
            noneMatch("item.price" lessOrEqualThan "1000"),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                "item.price" greaterOrEqualThan "10000",
            ),
            true
        ),
        Arguments.of(
            noneMatch(
                "item.price" lessOrEqualThan "1000",
                "item.price" greaterOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                "item.price" lessOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" lessOrEqualThan "1000",
                "item.price" lessOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                allMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                allMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            noneMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
    )

    @Suppress("LongMethod")
    private fun allMatchCases(): List = listOf(
        Arguments.of(
            allMatch("item.price" lessOrEqualThan "1000"),
            true
        ),
        Arguments.of(
            allMatch("item.price" greaterOrEqualThan "1000"),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                "item.price" lessOrEqualThan "1000",
            ),
            true
        ),
        Arguments.of(
            allMatch(
                "item.price" greaterOrEqualThan "1000",
                "item.price" lessOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                "item.price" greaterOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" greaterOrEqualThan "1000",
                "item.price" greaterOrEqualThan "1000",
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                allMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                allMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            allMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
    )

    @Suppress("LongMethod")
    private fun anyMatchCases(): List = listOf(
        Arguments.of(
            anyMatch("item.price" lessOrEqualThan "1000"),
            true
        ),
        Arguments.of(
            anyMatch("item.price" greaterOrEqualThan "1000"),
            false
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                "item.price" greaterOrEqualThan "1000"
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                "item.price" greaterOrEqualThan "1000"
            ),
            false
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                noneMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                noneMatch("item.price" lessOrEqualThan "1000")
            ),
            false
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                allMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                allMatch("item.price" lessOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                allMatch("item.price" greaterOrEqualThan "1000")
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                allMatch("item.price" greaterOrEqualThan "1000")
            ),
            false
        ),

        Arguments.of(
            anyMatch(
                "item.price" lessOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" lessOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" lessOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" greaterOrEqualThan "1000"),
            ),
            true
        ),
        Arguments.of(
            anyMatch(
                "item.price" greaterOrEqualThan "1000",
                anyMatch("item.price" greaterOrEqualThan "1000"),
                allMatch("item.price" greaterOrEqualThan "1000"),
                noneMatch("item.price" lessOrEqualThan "1000"),
            ),
            false
        ),
        Arguments.of(
            "item.arrTags" expContains "\"in_array\"",
            true
        ),
        Arguments.of(
            "item.arrTags" expContains "\"not_in_array\"",
            false
        ),
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy