LMAssembly // Add a test case for LMCoreEX.

This commit is contained in:
ShikiSuen 2023-03-02 21:08:33 +08:00
parent b5de4dd57d
commit 93812a7707
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
//// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
// StringView Ranges extension by (c) 2022 and onwards Isaac Xen (MIT License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.
import Foundation
import XCTest
@testable import LangModelAssembly
private let sampleData: String = #"""
#
# libTaBE (http://sourceforge.net/projects/libtabe/)
# (2002 ). 1999 Pai-Hsiang Hsiao BSD
#
-13.624335
-12.390804
-11.928720
-7.171551
-10.450457
-99.000000
-11.504072
-7.171052
-10.574273
-99.000000
-13.513987
-9.006414
-12.259095
-8.091803
-9.495858
-99.000000
"""#
final class LMCoreEXTests: XCTestCase {
func testLMCoreEXAsFactoryCoreDict() throws {
var lmTest = vChewingLM.LMCoreEX(
reverse: false, consolidate: false, defaultScore: 0, forceDefaultScore: false
)
lmTest.replaceData(textData: sampleData)
XCTAssertEqual(lmTest.count, 3)
let gao1 = lmTest.unigramsFor(key: "ㄍㄠ").map(\.value)
let ke1 = lmTest.unigramsFor(key: "ㄎㄜ").map(\.value)
let si1 = lmTest.unigramsFor(key: "").map(\.value)
XCTAssertEqual(gao1, ["", "", "", ""])
XCTAssertEqual(ke1, ["", "", "", "", ""])
XCTAssertEqual(si1, ["", "", "", "", "", "", ""])
}
}