datalogic-rs 4.0.21

A fast, type-safe Rust implementation of JSONLogic for evaluating logical rules as JSON. Perfect for business rules engines and dynamic filtering in Rust applications.
Documentation
[
    "# Collection of Modulo Operator Tests",
    {
        "description": "Modulo",
        "rule": { "%": [4, 2] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo (2)",
        "rule": { "%": [2, 2] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo (3)",
        "rule": { "%": [3, 2] },
        "result": 1,
        "data": null
    },
    {
        "description": "Modulo with a Decimal Operand",
        "rule": { "%": [1, 0.5] },
        "result": 0,
        "data": null,
        "decimal": true
    },
    {
        "description": "Modulo with Multiple Operands",
        "rule": { "%": [8, 6, 3] },
        "result": 2,
        "data": null
    },
    {
        "description": "Modulo with Multiple Operands (2)",
        "rule": { "%": [2, 2, 1] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo with Negative Numbers",
        "rule": { "%": [-1, 2] },
        "result": -1,
        "data": null
    },
    {
        "description": "Modulo with Strings",
        "rule": { "%": ["8", "2"] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo with Booleans",
        "rule": { "%": [false, true] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo with Multiple Value Types",
        "rule": { "%": ["8", 3, true] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo with Multiple Value Types (2)",
        "rule": { "%": ["1", 1] },
        "result": 0,
        "data": null
    },
    {
        "description": "Modulo with Single Operand (Number)",
        "rule": { "%": [1] },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo with Single Operand, Direct (Number)",
        "rule": { "%": 1 },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo with Single Operand, Direct (0)",
        "rule": { "%": 0 },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand (Number)",
        "rule": { "%": [1] },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand (Negative Number)",
        "rule": { "%": [-1] },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo with zero operands is an error",
        "rule": { "%": [] },
        "error": { "type": "Invalid Arguments" },
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (Number)",
        "rule": { "%": 1 },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (0)",
        "rule": { "%": 0 },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand (String)",
        "rule": { "%": ["1"] },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (Negative Number String)",
        "rule": { "%": "-1" },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },

    {
        "description": "Modulo Operator with Single Operand, Direct (String 0)",
        "rule": { "%": "0" },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (true)",
        "rule": { "%": true },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (false)",
        "rule": { "%": false },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with Single Operand, Direct (Empty String)",
        "rule": { "%": "" },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo Operator with a Single Operand, Direct (null)",
        "rule": { "%": null },
        "error": { "type": "Invalid Arguments"},
        "data": null
    },
    {
        "description": "Modulo with val",
        "rule": { "%": [{ "val": "x" }, { "val": "y" }] },
        "data": { "x": 11, "y": 6 },
        "result": 5
    },
    {
        "description": "Modulo with string produces NaN",
        "rule": { "%": ["Hey", 1] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Modulo with array produces NaN",
        "rule": { "%": [[1], 1] },
        "error": { "type": "NaN" },
        "data": null
    },
    {
        "description": "Modulo with a negative dividend",
        "rule": { "%": [-8, 3] },
        "result": -2,
        "data": null
    },
    { 
        "description": "Modulo with a negative divisor",
        "rule": { "%": [8, -3] },
        "result": 2,
        "data": null
    }
]