mirror of
https://github.com/laosb/ReadabilityFramework.git
synced 2025-07-09 20:35:32 +00:00
Basics.
This commit is contained in:
parent
2640bebf90
commit
d3dcfc84de
13 changed files with 352 additions and 41 deletions
|
@ -1,11 +0,0 @@
|
|||
import XCTest
|
||||
@testable import ReadabilityFramework
|
||||
|
||||
final class ReadabilityFrameworkTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
// This is an example of a functional test case.
|
||||
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||
// results.
|
||||
XCTAssertEqual(ReadabilityFramework().text, "Hello, World!")
|
||||
}
|
||||
}
|
32
Tests/ReadabilityTests/CommonMetrics.swift
Normal file
32
Tests/ReadabilityTests/CommonMetrics.swift
Normal file
|
@ -0,0 +1,32 @@
|
|||
import XCTest
|
||||
@testable import Readability
|
||||
|
||||
final class CommonMetrics: XCTestCase {
|
||||
func testOnlyWordCount() throws {
|
||||
let calc = RACommonMetricsCalculator(metrics: [.wordCount])
|
||||
|
||||
let results = calc.calculate(on: "Hello, World!")
|
||||
|
||||
XCTAssertEqual(results, [.wordCount: 2.0])
|
||||
}
|
||||
|
||||
func testAllMetrics() throws {
|
||||
let calc = RACommonMetricsCalculator(metrics: [
|
||||
.syllableCount,
|
||||
.wordCount,
|
||||
.sentenceCount,
|
||||
.avgSyllablesPerWord,
|
||||
.avgWordsPerSentence,
|
||||
])
|
||||
|
||||
let results = calc.calculate(on: "Hello, World!")
|
||||
|
||||
XCTAssertEqual(results, [
|
||||
.syllableCount: 3.0,
|
||||
.wordCount: 2.0,
|
||||
.sentenceCount: 1.0,
|
||||
.avgSyllablesPerWord: 1.5,
|
||||
.avgWordsPerSentence: 2.0
|
||||
])
|
||||
}
|
||||
}
|
28
Tests/ReadabilityTests/Tokenization.swift
Normal file
28
Tests/ReadabilityTests/Tokenization.swift
Normal file
|
@ -0,0 +1,28 @@
|
|||
import XCTest
|
||||
@testable import Readability
|
||||
|
||||
final class Tokenization: XCTestCase {
|
||||
func testHelloWorldSentence() throws {
|
||||
let tokenizer = RATokenizer("Hello, world!", unit: .sentence)
|
||||
|
||||
var results: [String] = []
|
||||
let count = tokenizer.enumerateTokens { sent in
|
||||
results.append(sent)
|
||||
}
|
||||
|
||||
XCTAssertEqual(count, 1)
|
||||
XCTAssertEqual(results, ["Hello, world!"])
|
||||
}
|
||||
|
||||
func testHelloWorldWord() throws {
|
||||
let tokenizer = RATokenizer("Hello, world!", unit: .word)
|
||||
|
||||
var results: [String] = []
|
||||
let count = tokenizer.enumerateTokens { sent in
|
||||
results.append(sent)
|
||||
}
|
||||
|
||||
XCTAssertEqual(count, 2)
|
||||
XCTAssertEqual(results, ["Hello", "world"])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue