This commit is contained in:
narawat lamaiin
2025-03-27 13:09:20 +07:00
parent 840b0e6205
commit 562f528c01
3 changed files with 87 additions and 26 deletions

View File

@@ -1,23 +1,18 @@
using Test
using GeneralUtils
@testset "detect_keyword tests" begin
@test GeneralUtils.detect_keyword(["test"], "this is a test string") == Dict("test" => 1)
@test GeneralUtils.detect_keyword(["hello", "world"], "hello world") == Dict("hello" => 1, "world" => 1)
@test GeneralUtils.detect_keyword(["missing"], "no keyword here") == Dict("missing" => nothing)
@test GeneralUtils.detect_keyword(["a", "b"], "a a b b b") == Dict("a" => 2, "b" => 3)
@test GeneralUtils.detect_keyword(String[], "empty keywords") == Dict{String, Any}()
@test GeneralUtils.detect_keyword(["keyword"], "") == Dict("keyword" => nothing)
@test GeneralUtils.detect_keyword(["case"], "CASE case Case cAsE") == Dict("case" => 4)
mixed_results = GeneralUtils.detect_keyword(["found", "notfound"], "found found found")
@test mixed_results["found"] == 3
@test mixed_results["notfound"] === nothing
special_chars = GeneralUtils.detect_keyword(["test!"], "test! test? test.")
@test special_chars["test!"] == 1
@testset "lastElementsIndex" begin
@test GeneralUtils.lastElementsIndex([1,2,3,4,5], 3) == 3:5
@test GeneralUtils.lastElementsIndex([1,2,3], 5) == 1:3
@test GeneralUtils.lastElementsIndex([1], 1) == 1:1
@test GeneralUtils.lastElementsIndex(collect(1:10), 4) == 7:10
@test GeneralUtils.lastElementsIndex(Float64[], 2) == 1:0
@test GeneralUtils.lastElementsIndex([1,2,3], 0) == length([1,2,3])+1:length([1,2,3])
@test GeneralUtils.lastElementsIndex(["a","b","c"], 2) == 2:3
end