diff --git a/Source/StringScore.swift b/Source/StringScore.swift index e5fc4b9..702682b 100644 --- a/Source/StringScore.swift +++ b/Source/StringScore.swift @@ -2,7 +2,7 @@ // Based on string_score 0.1.21 by Joshaven Potter. // https://github.com/joshaven/string_score/ // -// Copyright (c) 2016 YICHI ZHANG +// Copyright (c) 2016-present YICHI ZHANG // https://github.com/yichizhang // zhang-yi-chi@hotmail.com // @@ -27,97 +27,113 @@ import Foundation +private extension String { + + func charAt(_ i: Int) -> Character { + let index = self.index(self.startIndex, offsetBy: i) + return self[index] + } + + func charStrAt(_ i: Int) -> String { + return String(charAt(i)) + } +} + public extension String { + + func score(word: String, fuzziness: Double? = nil) -> Double { + + // If the string is equal to the word, perfect match. + if self == word { + return 1 + } + + //if it's not a perfect match and is empty return 0 + if word.isEmpty || self.isEmpty { + return 0 + } + + var runningScore = 0.0 + var charScore = 0.0 + var finalScore = 0.0 + + let string = self + let lString = string.lowercased() + let strLength = string.count + let lWord = word.lowercased() + let wordLength = word.count + + var idxOf: String.Index! + var startAt = lString.startIndex + var fuzzies = 1.0 + var fuzzyFactor = 0.0 + var fuzzinessIsNil = true + + // Cache fuzzyFactor for speed increase + if let fuzziness = fuzziness { + fuzzyFactor = 1 - fuzziness + fuzzinessIsNil = false + } - func score(word: String, fuzziness: Double? = nil) -> Double { + for i in 0 ..< wordLength { + // Find next first case-insensitive match of word's i-th character. + // The search in "string" begins at "startAt". + + if let range = lString.range( + of: lWord.charStrAt(i), + options: [.caseInsensitive, .diacriticInsensitive], + range: Range(startAt..(startAt.. @@ -46,7 +45,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/StringScore.xcodeproj/xcshareddata/xcschemes/SwiftyStringScore.xcscheme b/StringScore.xcodeproj/xcshareddata/xcschemes/SwiftyStringScore.xcscheme index ae0c1e0..ab2ba08 100644 --- a/StringScore.xcodeproj/xcshareddata/xcschemes/SwiftyStringScore.xcscheme +++ b/StringScore.xcodeproj/xcshareddata/xcschemes/SwiftyStringScore.xcscheme @@ -1,6 +1,6 @@ Bool { - var window: UIWindow? - - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - - return true - } + return true + } } diff --git a/StringScoreDemo/CustomInputViewController.swift b/StringScoreDemo/CustomInputViewController.swift index 110071c..f6b34a3 100644 --- a/StringScoreDemo/CustomInputViewController.swift +++ b/StringScoreDemo/CustomInputViewController.swift @@ -11,80 +11,80 @@ import SwiftyStringScore class CustomInputViewController: UIViewController, UITextViewDelegate { - @IBOutlet weak var sourceTextView: UITextView! - @IBOutlet weak var searchTextField: UITextField! - @IBOutlet weak var fuzzinessSlider: UISlider! - @IBOutlet weak var resultLabel: UILabel! - - func commonInit() - { - self.title = "Custom Input" - self.tabBarItem = UITabBarItem(title: self.title, image: DemoStyleKit.imageOf(string: "B"), tag: 1) - } - - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) - { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) - - commonInit() - } - - required init?(coder aDecoder: NSCoder) - { - super.init(coder: aDecoder) - commonInit() - } - - override func viewDidLoad() - { - super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. - - searchTextField.text = "Alice 😄 😅 " - - sourceTextView.text = "Alice has a Dingo. 😄 😅 😆 Alice lives in Wonderland." - sourceTextView.delegate = self - - searchTextField.addTarget(self, action: #selector(controlValueChanged(_:)), for: UIControlEvents.editingChanged) - fuzzinessSlider.addTarget(self, action: #selector(controlValueChanged(_:)), for: UIControlEvents.valueChanged) - - self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(backgroundTouched(_:)))) - - updateStringScore() - } - - override func didReceiveMemoryWarning() - { - super.didReceiveMemoryWarning() - // Dispose of any resources that can be recreated. - } - - // MARK: Slider value changed - @objc func controlValueChanged(_ sender: AnyObject) - { - updateStringScore() - } - - // MARK: Background touched - @objc func backgroundTouched(_ sender: AnyObject) - { - sourceTextView.resignFirstResponder() - searchTextField.resignFirstResponder() - } - - // MARK: Update - func updateStringScore() - { - if let sourceText = sourceTextView.text, let searchText = searchTextField.text { - let score = sourceText.score(word: searchText, fuzziness: Double(fuzzinessSlider.value)) - resultLabel.text = score.yz_toString() - } - } - - // MARK: UITextViewDelegate - func textViewDidChange(_ textView: UITextView) - { - updateStringScore() + @IBOutlet weak var sourceTextView: UITextView! + @IBOutlet weak var searchTextField: UITextField! + @IBOutlet weak var fuzzinessSlider: UISlider! + @IBOutlet weak var resultLabel: UILabel! + + func commonInit() + { + self.title = "Custom Input" + self.tabBarItem = UITabBarItem(title: self.title, image: DemoStyleKit.imageOf(string: "B"), tag: 1) + } + + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) + { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + + commonInit() + } + + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + commonInit() + } + + override func viewDidLoad() + { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + + searchTextField.text = "Alice 😄 😅 " + + sourceTextView.text = "Alice has a Dingo. 😄 😅 😆 Alice lives in Wonderland." + sourceTextView.delegate = self + + searchTextField.addTarget(self, action: #selector(controlValueChanged(_:)), for: UIControlEvents.editingChanged) + fuzzinessSlider.addTarget(self, action: #selector(controlValueChanged(_:)), for: UIControlEvents.valueChanged) + + self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(backgroundTouched(_:)))) + + updateStringScore() + } + + override func didReceiveMemoryWarning() + { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + // MARK: Slider value changed + @objc func controlValueChanged(_ sender: AnyObject) + { + updateStringScore() + } + + // MARK: Background touched + @objc func backgroundTouched(_ sender: AnyObject) + { + sourceTextView.resignFirstResponder() + searchTextField.resignFirstResponder() + } + + // MARK: Update + func updateStringScore() + { + if let sourceText = sourceTextView.text, let searchText = searchTextField.text { + let score = sourceText.score(word: searchText, fuzziness: Double(fuzzinessSlider.value)) + resultLabel.text = score.yz_toString() } + } + + // MARK: UITextViewDelegate + func textViewDidChange(_ textView: UITextView) + { + updateStringScore() + } } diff --git a/StringScoreDemo/DemoSearchTableController.swift b/StringScoreDemo/DemoSearchTableController.swift index ec1493e..3333ba6 100644 --- a/StringScoreDemo/DemoSearchTableController.swift +++ b/StringScoreDemo/DemoSearchTableController.swift @@ -14,167 +14,167 @@ typealias NameAndScoreTuple = (name:String, score:Double) class DemoSearchTableController: UITableViewController, UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating { - lazy var dataSourceArray: [String] = { - if let path = Bundle.main.path(forResource: "name_list", ofType: "txt"), - let data = try? Data(contentsOf: URL(fileURLWithPath: path)), - let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as? String - { - var arr = string.components(separatedBy: "\n") - - arr.sort { - (a, b) -> Bool in - return a < b - } - return arr - } - return [] - }() - - let defaultCellReuseIdentifier = "CellId" - - var searchController: UISearchController! - var resultsTableController: ResultsTableController! - - - func commonInit() - { - self.title = "Search" - self.tabBarItem = UITabBarItem(title: self.title, image: DemoStyleKit.imageOf(string: "A"), tag: 0) - } - - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) + lazy var dataSourceArray: [String] = { + if let path = Bundle.main.path(forResource: "name_list", ofType: "txt"), + let data = try? Data(contentsOf: URL(fileURLWithPath: path)), + let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) - - commonInit() + var arr = string.components(separatedBy: "\n") + + arr.sort { + (a, b) -> Bool in + return a < b + } + return arr } - - required init?(coder aDecoder: NSCoder) - { - super.init(coder: aDecoder) - commonInit() + return [] + }() + + let defaultCellReuseIdentifier = "CellId" + + var searchController: UISearchController! + var resultsTableController: ResultsTableController! + + + func commonInit() + { + self.title = "Search" + self.tabBarItem = UITabBarItem(title: self.title, image: DemoStyleKit.imageOf(string: "A"), tag: 0) + } + + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) + { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + + commonInit() + } + + required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + commonInit() + } + + override func viewDidLoad() + { + super.viewDidLoad() + + resultsTableController = ResultsTableController() + + // We want to be the delegate for our filtered table so didSelectRowAtIndexPath(_:) is called for both tables. + resultsTableController.tableView.delegate = self + + + searchController = UISearchController(searchResultsController: resultsTableController) + searchController.searchResultsUpdater = self + searchController.searchBar.sizeToFit() + + if #available(iOS 11.0, *) { + navigationItem.searchController = searchController } - - override func viewDidLoad() - { - super.viewDidLoad() + + searchController.delegate = self + searchController.dimsBackgroundDuringPresentation = false // default is YES + searchController.searchBar.delegate = self // so we can monitor text changes + others + + // Search is now just presenting a view controller. As such, normal view controller + // presentation semantics apply. Namely that presentation will walk up the view controller + // hierarchy until it finds the root view controller or one that defines a presentation context. + definesPresentationContext = true + + tableView.register(UITableViewCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier) + } + + // MARK: Table View Data Source and Delegate methods + override func numberOfSections(in tableView: UITableView) -> Int + { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int + { + return dataSourceArray.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell + { + let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: defaultCellReuseIdentifier) + + cell.textLabel?.text = dataSourceArray[(indexPath as NSIndexPath).row] + cell.detailTextLabel?.text = "" + + return cell + } + + // MARK: UISearchBarDelegate + func searchBarSearchButtonClicked(_ searchBar: UISearchBar) + { + searchBar.resignFirstResponder() + } + + // MARK: UISearchResultsUpdating + + func updateSearchResults(for searchController: UISearchController) + { + if let searchText = searchController.searchBar.text { + var resultArray: Array = Array() + for name in dataSourceArray { + let score = name.score(word: searchText) - resultsTableController = ResultsTableController() - - // We want to be the delegate for our filtered table so didSelectRowAtIndexPath(_:) is called for both tables. - resultsTableController.tableView.delegate = self - - - searchController = UISearchController(searchResultsController: resultsTableController) - searchController.searchResultsUpdater = self - searchController.searchBar.sizeToFit() - - if #available(iOS 11.0, *) { - navigationItem.searchController = searchController - } - - searchController.delegate = self - searchController.dimsBackgroundDuringPresentation = false // default is YES - searchController.searchBar.delegate = self // so we can monitor text changes + others - - // Search is now just presenting a view controller. As such, normal view controller - // presentation semantics apply. Namely that presentation will walk up the view controller - // hierarchy until it finds the root view controller or one that defines a presentation context. - definesPresentationContext = true - - tableView.register(UITableViewCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier) - } - - // MARK: Table View Data Source and Delegate methods - override func numberOfSections(in tableView: UITableView) -> Int - { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int - { - return dataSourceArray.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell - { - let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: defaultCellReuseIdentifier) - - cell.textLabel?.text = dataSourceArray[(indexPath as NSIndexPath).row] - cell.detailTextLabel?.text = "" - - return cell - } - - // MARK: UISearchBarDelegate - func searchBarSearchButtonClicked(_ searchBar: UISearchBar) - { - searchBar.resignFirstResponder() - } - - // MARK: UISearchResultsUpdating - - func updateSearchResults(for searchController: UISearchController) - { - if let searchText = searchController.searchBar.text { - var resultArray: Array = Array() - for name in dataSourceArray { - let score = name.score(word: searchText) - - let t = (name: name, score: score) - resultArray.append(t) - } - - resultArray.sort - { - (a, b) -> Bool in - a.score > b.score - } - - // Hand over the filtered results to our search results table. - let resultsController = searchController.searchResultsController as! ResultsTableController - resultsController.searchResultArray = resultArray - resultsController.tableView.reloadData() - } + let t = (name: name, score: score) + resultArray.append(t) + } + + resultArray.sort + { + (a, b) -> Bool in + a.score > b.score + } + + // Hand over the filtered results to our search results table. + let resultsController = searchController.searchResultsController as! ResultsTableController + resultsController.searchResultArray = resultArray + resultsController.tableView.reloadData() } + } } class ResultsTableController: UITableViewController, UISearchControllerDelegate { - var searchResultArray: [NameAndScoreTuple]! - - let defaultCellReuseIdentifier = "CellId" - - override func viewDidLoad() - { - super.viewDidLoad() - - tableView.register(UITableViewCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier) - } - - // MARK: Table View Data Source and Delegate methods - override func numberOfSections(in tableView: UITableView) -> Int - { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int - { - return searchResultArray.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell - { - let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: defaultCellReuseIdentifier) - - let t = searchResultArray[(indexPath as NSIndexPath).row] - - cell.textLabel?.text = t.name - cell.detailTextLabel?.text = t.score.yz_toString() - - let maxBlackProportion: CGFloat = 0.7 - cell.textLabel?.textColor = UIColor(white: maxBlackProportion * CGFloat(1 - t.score), alpha: 1.0) - - return cell - } + var searchResultArray: [NameAndScoreTuple]! + + let defaultCellReuseIdentifier = "CellId" + + override func viewDidLoad() + { + super.viewDidLoad() + + tableView.register(UITableViewCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier) + } + + // MARK: Table View Data Source and Delegate methods + override func numberOfSections(in tableView: UITableView) -> Int + { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int + { + return searchResultArray.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell + { + let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: defaultCellReuseIdentifier) + + let t = searchResultArray[(indexPath as NSIndexPath).row] + + cell.textLabel?.text = t.name + cell.detailTextLabel?.text = t.score.yz_toString() + + let maxBlackProportion: CGFloat = 0.7 + cell.textLabel?.textColor = UIColor(white: maxBlackProportion * CGFloat(1 - t.score), alpha: 1.0) + + return cell + } } diff --git a/StringScoreDemo/DemoStyleKit.swift b/StringScoreDemo/DemoStyleKit.swift index 5c7837b..3ee8f82 100644 --- a/StringScoreDemo/DemoStyleKit.swift +++ b/StringScoreDemo/DemoStyleKit.swift @@ -1,72 +1,72 @@ /* - -Copyright (c) 2015 Yichi Zhang -https://github.com/yichizhang -zhang-yi-chi@hotmail.com - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/ + + Copyright (c) 2015 Yichi Zhang + https://github.com/yichizhang + zhang-yi-chi@hotmail.com + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ import UIKit open class DemoStyleKit: NSObject { - class var mainFont: UIFont - { - return UIFont(name: "HelveticaNeue-Bold", size: 20)! - } - - //// Cache - - fileprivate struct Cache - { - static var imageDict: [String:UIImage] = Dictionary() - // static var oneTargets: [AnyObject]? - } - - //// Drawing Methods - - open class func draw(string: String) - { - //// General Declarations - let context = UIGraphicsGetCurrentContext() - - //// Text Drawing - let textRect = CGRect(x: 0, y: 0, width: 25, height: 25) - let textTextContent = NSString(string: string) - let textStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle - textStyle.alignment = NSTextAlignment.center - - let textFontAttributes = [NSAttributedStringKey.font: DemoStyleKit.mainFont, NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.paragraphStyle: textStyle] - - let textTextHeight: CGFloat = textTextContent.boundingRect(with: CGSize(width: textRect.width, height: CGFloat.infinity), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: textFontAttributes, context: nil).size.height - context?.saveGState() - context?.clip(to: textRect); - textTextContent.draw(in: CGRect(x: textRect.minX, y: textRect.minY + (textRect.height - textTextHeight) / 2, width: textRect.width, height: textTextHeight), withAttributes: textFontAttributes) - context?.restoreGState() - } - - //// Generated Images - - open class func imageOf(string: String) -> UIImage - { - if let image = Cache.imageDict[string] { - return image - } - - UIGraphicsBeginImageContextWithOptions(CGSize(width: 25, height: 25), false, 0) - DemoStyleKit.draw(string: string) - - let image = UIGraphicsGetImageFromCurrentImageContext()! - UIGraphicsEndImageContext() - - Cache.imageDict[string] = image - - return image + class var mainFont: UIFont + { + return UIFont(name: "HelveticaNeue-Bold", size: 20)! + } + + //// Cache + + fileprivate struct Cache + { + static var imageDict: [String:UIImage] = Dictionary() + // static var oneTargets: [AnyObject]? + } + + //// Drawing Methods + + open class func draw(string: String) + { + //// General Declarations + let context = UIGraphicsGetCurrentContext() + + //// Text Drawing + let textRect = CGRect(x: 0, y: 0, width: 25, height: 25) + let textTextContent = NSString(string: string) + let textStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle + textStyle.alignment = NSTextAlignment.center + + let textFontAttributes = [NSAttributedStringKey.font: DemoStyleKit.mainFont, NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.paragraphStyle: textStyle] + + let textTextHeight: CGFloat = textTextContent.boundingRect(with: CGSize(width: textRect.width, height: CGFloat.infinity), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: textFontAttributes, context: nil).size.height + context?.saveGState() + context?.clip(to: textRect); + textTextContent.draw(in: CGRect(x: textRect.minX, y: textRect.minY + (textRect.height - textTextHeight) / 2, width: textRect.width, height: textTextHeight), withAttributes: textFontAttributes) + context?.restoreGState() + } + + //// Generated Images + + open class func imageOf(string: String) -> UIImage + { + if let image = Cache.imageDict[string] { + return image } + + UIGraphicsBeginImageContextWithOptions(CGSize(width: 25, height: 25), false, 0) + DemoStyleKit.draw(string: string) + + let image = UIGraphicsGetImageFromCurrentImageContext()! + UIGraphicsEndImageContext() + + Cache.imageDict[string] = image + + return image + } } diff --git a/StringScoreDemo/Extensions.swift b/StringScoreDemo/Extensions.swift index c72d367..45d2d5d 100644 --- a/StringScoreDemo/Extensions.swift +++ b/StringScoreDemo/Extensions.swift @@ -10,8 +10,8 @@ import Foundation extension Double { - func yz_toString() -> String - { - return NSString(format: "%.3f", self) as String - } -} \ No newline at end of file + func yz_toString() -> String + { + return NSString(format: "%.3f", self) as String + } +} diff --git a/StringScoreDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/StringScoreDemo/Images.xcassets/AppIcon.appiconset/Contents.json index eeea76c..d8db8d6 100644 --- a/StringScoreDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/StringScoreDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -64,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/StringScoreTests/StringScoreTests.swift b/StringScoreTests/StringScoreTests.swift index 542c165..321c5fa 100644 --- a/StringScoreTests/StringScoreTests.swift +++ b/StringScoreTests/StringScoreTests.swift @@ -3,30 +3,40 @@ import Quick import Nimble import SwiftyStringScore -class StringScoreTestSpec: QuickSpec -{ - var testCaseArray: [StringScoreTestCase]! - var precision: Double! - - override func setUp() - { - super.setUp() +class StringScoreTestSpec: QuickSpec { + + var testCaseArray: [TestCase]! + var precision: Double! + + override func setUp() { + super.setUp() + } + + override func spec() { + precision = 0.00001 + + describe("score of") { + for testCase in TestCases.default { + context(testCase.description, { + it("is \(testCase.score)", closure: { + let actualScore = testCase.text.score(word: testCase.keyword, fuzziness: testCase.fz) + + expect(actualScore).to(beCloseTo(testCase.score, within: self.precision)) + }) + }) + } } - override func spec() - { - testCaseArray = StringScoreTestCaseManager.defaultTestCaseArray() - precision = 0.00001 - - describe("String scores") { - for testCase in self.testCaseArray { - context(testCase.description, { - it("Returns correct score", closure: { - let actualScore = testCase.text.score(word: testCase.searchString, fuzziness: testCase.fuzziness) - - expect(actualScore).to(beCloseTo(testCase.expectedScore, within: self.precision)) - }) - }) - } - } + + describe("score of") { + for testCase in TestCases.diacritics { + context(testCase.description, { + it("is \(testCase.score)", closure: { + let actualScore = testCase.text.score(word: testCase.keyword, fuzziness: testCase.fz) + + expect(actualScore).to(beCloseTo(testCase.score, within: self.precision)) + }) + }) + } } + } } diff --git a/StringScoreTests/TestHelper.swift b/StringScoreTests/TestHelper.swift index ee9c244..74afe22 100644 --- a/StringScoreTests/TestHelper.swift +++ b/StringScoreTests/TestHelper.swift @@ -1,279 +1,355 @@ import Foundation -struct StringScoreTestCase: CustomStringConvertible -{ - var text: String! - var searchString: String! - var fuzziness: Double? - var expectedScore: Double! - - var description: String { - let fuzzinessString = fuzziness == nil ? "nil" : "\(fuzziness!)" - return "Searching \"\(searchString)\" in \"\(text)\" with fuzziness \(fuzzinessString)" +struct TestCase: CustomStringConvertible { + + var text: String + var keyword: String + var fz: Double? + var score: Double + + var description: String { + + var desc = "\"\(keyword)\" in \"\(text)\"" + if let fuzziness = self.fz { + desc += " fz \(fuzziness)" } + + return desc + } } -class StringScoreTestCaseManager -{ - class func defaultTestCaseArray() -> [StringScoreTestCase] - { - return [ - StringScoreTestCase(text: "hello world", searchString: "axl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "hello world", searchString: "ow", fuzziness: nil, expectedScore: 0.354545454545455), - StringScoreTestCase(text: "hello world", searchString: "e", fuzziness: nil, expectedScore: 0.109090909090909), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: nil, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "he", fuzziness: nil, expectedScore: 0.622727272727273), - StringScoreTestCase(text: "hello world", searchString: "hel", fuzziness: nil, expectedScore: 0.659090909090909), - StringScoreTestCase(text: "hello world", searchString: "hell", fuzziness: nil, expectedScore: 0.695454545454545), - StringScoreTestCase(text: "hello world", searchString: "hello", fuzziness: nil, expectedScore: 0.731818181818182), - StringScoreTestCase(text: "hello world", searchString: "hello worl", fuzziness: nil, expectedScore: 0.913636363636364), - StringScoreTestCase(text: "hello world", searchString: "hello world", fuzziness: nil, expectedScore: 1.0), - StringScoreTestCase(text: "hello world", searchString: "hello wor1", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: nil, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "H", fuzziness: nil, expectedScore: 0.531818181818182), - StringScoreTestCase(text: "hello world", searchString: "HiMi", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "hello world", searchString: "Hills", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "hello world", searchString: "Hillsd", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "axl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "ow", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "e", fuzziness: nil, expectedScore: 0.15), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: nil, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "he", fuzziness: nil, expectedScore: 0.9), - StringScoreTestCase(text: "He", searchString: "hel", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "hell", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "hello", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "hello worl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "hello world", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "hello wor1", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: nil, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "H", fuzziness: nil, expectedScore: 0.75), - StringScoreTestCase(text: "He", searchString: "HiMi", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "Hills", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "Hillsd", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "axl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "ow", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "e", fuzziness: nil, expectedScore: 0.12), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: nil, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "he", fuzziness: nil, expectedScore: 0.675), - StringScoreTestCase(text: "Hello", searchString: "hel", fuzziness: nil, expectedScore: 0.763333333333333), - StringScoreTestCase(text: "Hello", searchString: "hell", fuzziness: nil, expectedScore: 0.8475), - StringScoreTestCase(text: "Hello", searchString: "hello", fuzziness: nil, expectedScore: 0.93), - StringScoreTestCase(text: "Hello", searchString: "hello worl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "hello world", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "hello wor1", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: nil, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "H", fuzziness: nil, expectedScore: 0.63), - StringScoreTestCase(text: "Hello", searchString: "HiMi", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "Hills", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hello", searchString: "Hillsd", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "axl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "ow", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "e", fuzziness: nil, expectedScore: 0.105555555555556), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: nil, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "he", fuzziness: nil, expectedScore: 0.4), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hel", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hell", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello worl", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello world", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello wor1", fuzziness: nil, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: nil, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "H", fuzziness: nil, expectedScore: 0.572222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "HiMi", fuzziness: nil, expectedScore: 0.669444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hills", fuzziness: nil, expectedScore: 0.661111111111111), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hillsd", fuzziness: nil, expectedScore: 0.683333333333333), - StringScoreTestCase(text: "hello world", searchString: "axl", fuzziness: 0.5, expectedScore: 0.0212121212121212), - StringScoreTestCase(text: "hello world", searchString: "ow", fuzziness: 0.5, expectedScore: 0.354545454545455), - StringScoreTestCase(text: "hello world", searchString: "e", fuzziness: 0.5, expectedScore: 0.109090909090909), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 0.5, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "he", fuzziness: 0.5, expectedScore: 0.622727272727273), - StringScoreTestCase(text: "hello world", searchString: "hel", fuzziness: 0.5, expectedScore: 0.659090909090909), - StringScoreTestCase(text: "hello world", searchString: "hell", fuzziness: 0.5, expectedScore: 0.695454545454545), - StringScoreTestCase(text: "hello world", searchString: "hello", fuzziness: 0.5, expectedScore: 0.731818181818182), - StringScoreTestCase(text: "hello world", searchString: "hello worl", fuzziness: 0.5, expectedScore: 0.913636363636364), - StringScoreTestCase(text: "hello world", searchString: "hello world", fuzziness: 0.5, expectedScore: 1.0), - StringScoreTestCase(text: "hello world", searchString: "hello wor1", fuzziness: 0.5, expectedScore: 0.608181818181818), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 0.5, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "H", fuzziness: 0.5, expectedScore: 0.531818181818182), - StringScoreTestCase(text: "hello world", searchString: "HiMi", fuzziness: 0.5, expectedScore: 0.197727272727273), - StringScoreTestCase(text: "hello world", searchString: "Hills", fuzziness: 0.5, expectedScore: 0.273636363636364), - StringScoreTestCase(text: "hello world", searchString: "Hillsd", fuzziness: 0.5, expectedScore: 0.272348484848485), - StringScoreTestCase(text: "He", searchString: "axl", fuzziness: 0.5, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "ow", fuzziness: 0.5, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "e", fuzziness: 0.5, expectedScore: 0.15), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 0.5, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "he", fuzziness: 0.5, expectedScore: 0.9), - StringScoreTestCase(text: "He", searchString: "hel", fuzziness: 0.5, expectedScore: 0.566666666666667), - StringScoreTestCase(text: "He", searchString: "hell", fuzziness: 0.5, expectedScore: 0.43125), - StringScoreTestCase(text: "He", searchString: "hello", fuzziness: 0.5, expectedScore: 0.36), - StringScoreTestCase(text: "He", searchString: "hello worl", fuzziness: 0.5, expectedScore: 0.24), - StringScoreTestCase(text: "He", searchString: "hello world", fuzziness: 0.5, expectedScore: 0.230578512396694), - StringScoreTestCase(text: "He", searchString: "hello wor1", fuzziness: 0.5, expectedScore: 0.24), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 0.5, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "H", fuzziness: 0.5, expectedScore: 0.75), - StringScoreTestCase(text: "He", searchString: "HiMi", fuzziness: 0.5, expectedScore: 0.27), - StringScoreTestCase(text: "He", searchString: "Hills", fuzziness: 0.5, expectedScore: 0.243333333333333), - StringScoreTestCase(text: "He", searchString: "Hillsd", fuzziness: 0.5, expectedScore: 0.226190476190476), - StringScoreTestCase(text: "Hello", searchString: "axl", fuzziness: 0.5, expectedScore: 0.0266666666666667), - StringScoreTestCase(text: "Hello", searchString: "ow", fuzziness: 0.5, expectedScore: 0.0466666666666667), - StringScoreTestCase(text: "Hello", searchString: "e", fuzziness: 0.5, expectedScore: 0.12), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 0.5, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "he", fuzziness: 0.5, expectedScore: 0.675), - StringScoreTestCase(text: "Hello", searchString: "hel", fuzziness: 0.5, expectedScore: 0.763333333333333), - StringScoreTestCase(text: "Hello", searchString: "hell", fuzziness: 0.5, expectedScore: 0.8475), - StringScoreTestCase(text: "Hello", searchString: "hello", fuzziness: 0.5, expectedScore: 0.93), - StringScoreTestCase(text: "Hello", searchString: "hello worl", fuzziness: 0.5, expectedScore: 0.317142857142857), - StringScoreTestCase(text: "Hello", searchString: "hello world", fuzziness: 0.5, expectedScore: 0.291818181818182), - StringScoreTestCase(text: "Hello", searchString: "hello wor1", fuzziness: 0.5, expectedScore: 0.317142857142857), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 0.5, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "H", fuzziness: 0.5, expectedScore: 0.63), - StringScoreTestCase(text: "Hello", searchString: "HiMi", fuzziness: 0.5, expectedScore: 0.222), - StringScoreTestCase(text: "Hello", searchString: "Hills", fuzziness: 0.5, expectedScore: 0.33), - StringScoreTestCase(text: "Hello", searchString: "Hillsd", fuzziness: 0.5, expectedScore: 0.282), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "axl", fuzziness: 0.5, expectedScore: 0.12962962962963), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "ow", fuzziness: 0.5, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "e", fuzziness: 0.5, expectedScore: 0.105555555555556), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 0.5, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "he", fuzziness: 0.5, expectedScore: 0.4), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hel", fuzziness: 0.5, expectedScore: 0.266666666666667), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hell", fuzziness: 0.5, expectedScore: 0.21875), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello", fuzziness: 0.5, expectedScore: 0.196), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello worl", fuzziness: 0.5, expectedScore: 0.179382716049383), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello world", fuzziness: 0.5, expectedScore: 0.17489898989899), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello wor1", fuzziness: 0.5, expectedScore: 0.179382716049383), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 0.5, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "H", fuzziness: 0.5, expectedScore: 0.572222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "HiMi", fuzziness: 0.5, expectedScore: 0.669444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hills", fuzziness: 0.5, expectedScore: 0.661111111111111), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hillsd", fuzziness: 0.5, expectedScore: 0.683333333333333), - StringScoreTestCase(text: "hello world", searchString: "axl", fuzziness: 0.7, expectedScore: 0.0265151515151515), - StringScoreTestCase(text: "hello world", searchString: "ow", fuzziness: 0.7, expectedScore: 0.354545454545455), - StringScoreTestCase(text: "hello world", searchString: "e", fuzziness: 0.7, expectedScore: 0.109090909090909), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 0.7, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "he", fuzziness: 0.7, expectedScore: 0.622727272727273), - StringScoreTestCase(text: "hello world", searchString: "hel", fuzziness: 0.7, expectedScore: 0.659090909090909), - StringScoreTestCase(text: "hello world", searchString: "hell", fuzziness: 0.7, expectedScore: 0.695454545454545), - StringScoreTestCase(text: "hello world", searchString: "hello", fuzziness: 0.7, expectedScore: 0.731818181818182), - StringScoreTestCase(text: "hello world", searchString: "hello worl", fuzziness: 0.7, expectedScore: 0.913636363636364), - StringScoreTestCase(text: "hello world", searchString: "hello world", fuzziness: 0.7, expectedScore: 1.0), - StringScoreTestCase(text: "hello world", searchString: "hello wor1", fuzziness: 0.7, expectedScore: 0.678671328671329), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 0.7, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "H", fuzziness: 0.7, expectedScore: 0.531818181818182), - StringScoreTestCase(text: "hello world", searchString: "HiMi", fuzziness: 0.7, expectedScore: 0.212799043062201), - StringScoreTestCase(text: "hello world", searchString: "Hills", fuzziness: 0.7, expectedScore: 0.304545454545455), - StringScoreTestCase(text: "hello world", searchString: "Hillsd", fuzziness: 0.7, expectedScore: 0.302935606060606), - StringScoreTestCase(text: "He", searchString: "axl", fuzziness: 0.7, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "ow", fuzziness: 0.7, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "e", fuzziness: 0.7, expectedScore: 0.15), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 0.7, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "he", fuzziness: 0.7, expectedScore: 0.9), - StringScoreTestCase(text: "He", searchString: "hel", fuzziness: 0.7, expectedScore: 0.630769230769231), - StringScoreTestCase(text: "He", searchString: "hell", fuzziness: 0.7, expectedScore: 0.5015625), - StringScoreTestCase(text: "He", searchString: "hello", fuzziness: 0.7, expectedScore: 0.426315789473684), - StringScoreTestCase(text: "He", searchString: "hello worl", fuzziness: 0.7, expectedScore: 0.282352941176471), - StringScoreTestCase(text: "He", searchString: "hello world", fuzziness: 0.7, expectedScore: 0.26977886977887), - StringScoreTestCase(text: "He", searchString: "hello wor1", fuzziness: 0.7, expectedScore: 0.282352941176471), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 0.7, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "H", fuzziness: 0.7, expectedScore: 0.75), - StringScoreTestCase(text: "He", searchString: "HiMi", fuzziness: 0.7, expectedScore: 0.307894736842105), - StringScoreTestCase(text: "He", searchString: "Hills", fuzziness: 0.7, expectedScore: 0.277272727272727), - StringScoreTestCase(text: "He", searchString: "Hillsd", fuzziness: 0.7, expectedScore: 0.256666666666667), - StringScoreTestCase(text: "Hello", searchString: "axl", fuzziness: 0.7, expectedScore: 0.0333333333333333), - StringScoreTestCase(text: "Hello", searchString: "ow", fuzziness: 0.7, expectedScore: 0.0538461538461538), - StringScoreTestCase(text: "Hello", searchString: "e", fuzziness: 0.7, expectedScore: 0.12), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 0.7, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "he", fuzziness: 0.7, expectedScore: 0.675), - StringScoreTestCase(text: "Hello", searchString: "hel", fuzziness: 0.7, expectedScore: 0.763333333333333), - StringScoreTestCase(text: "Hello", searchString: "hell", fuzziness: 0.7, expectedScore: 0.8475), - StringScoreTestCase(text: "Hello", searchString: "hello", fuzziness: 0.7, expectedScore: 0.93), - StringScoreTestCase(text: "Hello", searchString: "hello worl", fuzziness: 0.7, expectedScore: 0.384), - StringScoreTestCase(text: "Hello", searchString: "hello world", fuzziness: 0.7, expectedScore: 0.352597402597403), - StringScoreTestCase(text: "Hello", searchString: "hello wor1", fuzziness: 0.7, expectedScore: 0.384), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 0.7, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "H", fuzziness: 0.7, expectedScore: 0.63), - StringScoreTestCase(text: "Hello", searchString: "HiMi", fuzziness: 0.7, expectedScore: 0.244736842105263), - StringScoreTestCase(text: "Hello", searchString: "Hills", fuzziness: 0.7, expectedScore: 0.375), - StringScoreTestCase(text: "Hello", searchString: "Hillsd", fuzziness: 0.7, expectedScore: 0.323684210526316), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "axl", fuzziness: 0.7, expectedScore: 0.14957264957265), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "ow", fuzziness: 0.7, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "e", fuzziness: 0.7, expectedScore: 0.105555555555556), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 0.7, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "he", fuzziness: 0.7, expectedScore: 0.4), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hel", fuzziness: 0.7, expectedScore: 0.284615384615385), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hell", fuzziness: 0.7, expectedScore: 0.2359375), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello", fuzziness: 0.7, expectedScore: 0.210526315789474), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello worl", fuzziness: 0.7, expectedScore: 0.192652329749104), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello world", fuzziness: 0.7, expectedScore: 0.186616161616162), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello wor1", fuzziness: 0.7, expectedScore: 0.192652329749104), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 0.7, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "H", fuzziness: 0.7, expectedScore: 0.572222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "HiMi", fuzziness: 0.7, expectedScore: 0.669444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hills", fuzziness: 0.7, expectedScore: 0.661111111111111), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hillsd", fuzziness: 0.7, expectedScore: 0.683333333333333), - StringScoreTestCase(text: "hello world", searchString: "axl", fuzziness: 1.0, expectedScore: 0.0424242424242424), - StringScoreTestCase(text: "hello world", searchString: "ow", fuzziness: 1.0, expectedScore: 0.354545454545455), - StringScoreTestCase(text: "hello world", searchString: "e", fuzziness: 1.0, expectedScore: 0.109090909090909), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 1.0, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "he", fuzziness: 1.0, expectedScore: 0.622727272727273), - StringScoreTestCase(text: "hello world", searchString: "hel", fuzziness: 1.0, expectedScore: 0.659090909090909), - StringScoreTestCase(text: "hello world", searchString: "hell", fuzziness: 1.0, expectedScore: 0.695454545454545), - StringScoreTestCase(text: "hello world", searchString: "hello", fuzziness: 1.0, expectedScore: 0.731818181818182), - StringScoreTestCase(text: "hello world", searchString: "hello worl", fuzziness: 1.0, expectedScore: 0.913636363636364), - StringScoreTestCase(text: "hello world", searchString: "hello world", fuzziness: 1.0, expectedScore: 1.0), - StringScoreTestCase(text: "hello world", searchString: "hello wor1", fuzziness: 1.0, expectedScore: 0.837272727272727), - StringScoreTestCase(text: "hello world", searchString: "h", fuzziness: 1.0, expectedScore: 0.586363636363636), - StringScoreTestCase(text: "hello world", searchString: "H", fuzziness: 1.0, expectedScore: 0.531818181818182), - StringScoreTestCase(text: "hello world", searchString: "HiMi", fuzziness: 1.0, expectedScore: 0.269318181818182), - StringScoreTestCase(text: "hello world", searchString: "Hills", fuzziness: 1.0, expectedScore: 0.397272727272727), - StringScoreTestCase(text: "hello world", searchString: "Hillsd", fuzziness: 1.0, expectedScore: 0.39469696969697), - StringScoreTestCase(text: "He", searchString: "axl", fuzziness: 1.0, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "ow", fuzziness: 1.0, expectedScore: 0.0), - StringScoreTestCase(text: "He", searchString: "e", fuzziness: 1.0, expectedScore: 0.15), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 1.0, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "he", fuzziness: 1.0, expectedScore: 0.9), - StringScoreTestCase(text: "He", searchString: "hel", fuzziness: 1.0, expectedScore: 0.775), - StringScoreTestCase(text: "He", searchString: "hell", fuzziness: 1.0, expectedScore: 0.7125), - StringScoreTestCase(text: "He", searchString: "hello", fuzziness: 1.0, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "hello worl", fuzziness: 1.0, expectedScore: 0.6), - StringScoreTestCase(text: "He", searchString: "hello world", fuzziness: 1.0, expectedScore: 0.593181818181818), - StringScoreTestCase(text: "He", searchString: "hello wor1", fuzziness: 1.0, expectedScore: 0.6), - StringScoreTestCase(text: "He", searchString: "h", fuzziness: 1.0, expectedScore: 0.675), - StringScoreTestCase(text: "He", searchString: "H", fuzziness: 1.0, expectedScore: 0.75), - StringScoreTestCase(text: "He", searchString: "HiMi", fuzziness: 1.0, expectedScore: 0.45), - StringScoreTestCase(text: "He", searchString: "Hills", fuzziness: 1.0, expectedScore: 0.43), - StringScoreTestCase(text: "He", searchString: "Hillsd", fuzziness: 1.0, expectedScore: 0.416666666666667), - StringScoreTestCase(text: "Hello", searchString: "axl", fuzziness: 1.0, expectedScore: 0.0533333333333333), - StringScoreTestCase(text: "Hello", searchString: "ow", fuzziness: 1.0, expectedScore: 0.07), - StringScoreTestCase(text: "Hello", searchString: "e", fuzziness: 1.0, expectedScore: 0.12), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 1.0, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "he", fuzziness: 1.0, expectedScore: 0.675), - StringScoreTestCase(text: "Hello", searchString: "hel", fuzziness: 1.0, expectedScore: 0.763333333333333), - StringScoreTestCase(text: "Hello", searchString: "hell", fuzziness: 1.0, expectedScore: 0.8475), - StringScoreTestCase(text: "Hello", searchString: "hello", fuzziness: 1.0, expectedScore: 0.93), - StringScoreTestCase(text: "Hello", searchString: "hello worl", fuzziness: 1.0, expectedScore: 0.735), - StringScoreTestCase(text: "Hello", searchString: "hello world", fuzziness: 1.0, expectedScore: 0.717272727272727), - StringScoreTestCase(text: "Hello", searchString: "hello wor1", fuzziness: 1.0, expectedScore: 0.735), - StringScoreTestCase(text: "Hello", searchString: "h", fuzziness: 1.0, expectedScore: 0.57), - StringScoreTestCase(text: "Hello", searchString: "H", fuzziness: 1.0, expectedScore: 0.63), - StringScoreTestCase(text: "Hello", searchString: "HiMi", fuzziness: 1.0, expectedScore: 0.33), - StringScoreTestCase(text: "Hello", searchString: "Hills", fuzziness: 1.0, expectedScore: 0.51), - StringScoreTestCase(text: "Hello", searchString: "Hillsd", fuzziness: 1.0, expectedScore: 0.48), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "axl", fuzziness: 1.0, expectedScore: 0.194444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "ow", fuzziness: 1.0, expectedScore: 0.0), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "e", fuzziness: 1.0, expectedScore: 0.105555555555556), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 1.0, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "he", fuzziness: 1.0, expectedScore: 0.4), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hel", fuzziness: 1.0, expectedScore: 0.325), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hell", fuzziness: 1.0, expectedScore: 0.2875), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello", fuzziness: 1.0, expectedScore: 0.265), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello worl", fuzziness: 1.0, expectedScore: 0.282222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello world", fuzziness: 1.0, expectedScore: 0.274494949494949), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "hello wor1", fuzziness: 1.0, expectedScore: 0.282222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "h", fuzziness: 1.0, expectedScore: 0.519444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "H", fuzziness: 1.0, expectedScore: 0.572222222222222), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "HiMi", fuzziness: 1.0, expectedScore: 0.669444444444444), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hills", fuzziness: 1.0, expectedScore: 0.661111111111111), - StringScoreTestCase(text: "Hillsdale Michigan", searchString: "Hillsd", fuzziness: 1.0, expectedScore: 0.683333333333333), - ] - } +class TestCases { + + static var `default`: [TestCase] = [ + TestCase(text: "", keyword: "", fz: nil, score: 1.0), + TestCase(text: "", keyword: "h", fz: nil, score: 0.0), + TestCase(text: "hello world", keyword: "", fz: nil, score: 0.0), + + TestCase(text: "hello world", keyword: "axl", fz: nil, score: 0.0), + TestCase(text: "hello world", keyword: "ow", fz: nil, score: 0.354545454545455), + TestCase(text: "hello world", keyword: "e", fz: nil, score: 0.109090909090909), + TestCase(text: "hello world", keyword: "h", fz: nil, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "he", fz: nil, score: 0.622727272727273), + TestCase(text: "hello world", keyword: "hel", fz: nil, score: 0.659090909090909), + TestCase(text: "hello world", keyword: "hell", fz: nil, score: 0.695454545454545), + TestCase(text: "hello world", keyword: "hello", fz: nil, score: 0.731818181818182), + TestCase(text: "hello world", keyword: "hello worl", fz: nil, score: 0.913636363636364), + TestCase(text: "hello world", keyword: "hello world", fz: nil, score: 1.0), + TestCase(text: "hello world", keyword: "hello wor1", fz: nil, score: 0.0), + TestCase(text: "hello world", keyword: "h", fz: nil, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "H", fz: nil, score: 0.531818181818182), + TestCase(text: "hello world", keyword: "HiMi", fz: nil, score: 0.0), + TestCase(text: "hello world", keyword: "Hills", fz: nil, score: 0.0), + TestCase(text: "hello world", keyword: "Hillsd", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "axl", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "ow", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "e", fz: nil, score: 0.15), + TestCase(text: "He", keyword: "h", fz: nil, score: 0.675), + TestCase(text: "He", keyword: "he", fz: nil, score: 0.9), + TestCase(text: "He", keyword: "hel", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "hell", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "hello", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "hello worl", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "hello world", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "hello wor1", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "h", fz: nil, score: 0.675), + TestCase(text: "He", keyword: "H", fz: nil, score: 0.75), + TestCase(text: "He", keyword: "HiMi", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "Hills", fz: nil, score: 0.0), + TestCase(text: "He", keyword: "Hillsd", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "axl", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "ow", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "e", fz: nil, score: 0.12), + TestCase(text: "Hello", keyword: "h", fz: nil, score: 0.57), + TestCase(text: "Hello", keyword: "he", fz: nil, score: 0.675), + TestCase(text: "Hello", keyword: "hel", fz: nil, score: 0.763333333333333), + TestCase(text: "Hello", keyword: "hell", fz: nil, score: 0.8475), + TestCase(text: "Hello", keyword: "hello", fz: nil, score: 0.93), + TestCase(text: "Hello", keyword: "hello worl", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "hello world", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "hello wor1", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "h", fz: nil, score: 0.57), + TestCase(text: "Hello", keyword: "H", fz: nil, score: 0.63), + TestCase(text: "Hello", keyword: "HiMi", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "Hills", fz: nil, score: 0.0), + TestCase(text: "Hello", keyword: "Hillsd", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "axl", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "ow", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "e", fz: nil, score: 0.105555555555556), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: nil, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "he", fz: nil, score: 0.4), + TestCase(text: "Hillsdale Michigan", keyword: "hel", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "hell", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "hello", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "hello worl", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "hello world", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "hello wor1", fz: nil, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: nil, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "H", fz: nil, score: 0.572222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "HiMi", fz: nil, score: 0.669444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "Hills", fz: nil, score: 0.661111111111111), + TestCase(text: "Hillsdale Michigan", keyword: "Hillsd", fz: nil, score: 0.683333333333333), + TestCase(text: "hello world", keyword: "axl", fz: 0.5, score: 0.0212121212121212), + TestCase(text: "hello world", keyword: "ow", fz: 0.5, score: 0.354545454545455), + TestCase(text: "hello world", keyword: "e", fz: 0.5, score: 0.109090909090909), + TestCase(text: "hello world", keyword: "h", fz: 0.5, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "he", fz: 0.5, score: 0.622727272727273), + TestCase(text: "hello world", keyword: "hel", fz: 0.5, score: 0.659090909090909), + TestCase(text: "hello world", keyword: "hell", fz: 0.5, score: 0.695454545454545), + TestCase(text: "hello world", keyword: "hello", fz: 0.5, score: 0.731818181818182), + TestCase(text: "hello world", keyword: "hello worl", fz: 0.5, score: 0.913636363636364), + TestCase(text: "hello world", keyword: "hello world", fz: 0.5, score: 1.0), + TestCase(text: "hello world", keyword: "hello wor1", fz: 0.5, score: 0.608181818181818), + TestCase(text: "hello world", keyword: "h", fz: 0.5, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "H", fz: 0.5, score: 0.531818181818182), + TestCase(text: "hello world", keyword: "HiMi", fz: 0.5, score: 0.197727272727273), + TestCase(text: "hello world", keyword: "Hills", fz: 0.5, score: 0.273636363636364), + TestCase(text: "hello world", keyword: "Hillsd", fz: 0.5, score: 0.272348484848485), + TestCase(text: "He", keyword: "axl", fz: 0.5, score: 0.0), + TestCase(text: "He", keyword: "ow", fz: 0.5, score: 0.0), + TestCase(text: "He", keyword: "e", fz: 0.5, score: 0.15), + TestCase(text: "He", keyword: "h", fz: 0.5, score: 0.675), + TestCase(text: "He", keyword: "he", fz: 0.5, score: 0.9), + TestCase(text: "He", keyword: "hel", fz: 0.5, score: 0.566666666666667), + TestCase(text: "He", keyword: "hell", fz: 0.5, score: 0.43125), + TestCase(text: "He", keyword: "hello", fz: 0.5, score: 0.36), + TestCase(text: "He", keyword: "hello worl", fz: 0.5, score: 0.24), + TestCase(text: "He", keyword: "hello world", fz: 0.5, score: 0.230578512396694), + TestCase(text: "He", keyword: "hello wor1", fz: 0.5, score: 0.24), + TestCase(text: "He", keyword: "h", fz: 0.5, score: 0.675), + TestCase(text: "He", keyword: "H", fz: 0.5, score: 0.75), + TestCase(text: "He", keyword: "HiMi", fz: 0.5, score: 0.27), + TestCase(text: "He", keyword: "Hills", fz: 0.5, score: 0.243333333333333), + TestCase(text: "He", keyword: "Hillsd", fz: 0.5, score: 0.226190476190476), + TestCase(text: "Hello", keyword: "axl", fz: 0.5, score: 0.0266666666666667), + TestCase(text: "Hello", keyword: "ow", fz: 0.5, score: 0.0466666666666667), + TestCase(text: "Hello", keyword: "e", fz: 0.5, score: 0.12), + TestCase(text: "Hello", keyword: "h", fz: 0.5, score: 0.57), + TestCase(text: "Hello", keyword: "he", fz: 0.5, score: 0.675), + TestCase(text: "Hello", keyword: "hel", fz: 0.5, score: 0.763333333333333), + TestCase(text: "Hello", keyword: "hell", fz: 0.5, score: 0.8475), + TestCase(text: "Hello", keyword: "hello", fz: 0.5, score: 0.93), + TestCase(text: "Hello", keyword: "hello worl", fz: 0.5, score: 0.317142857142857), + TestCase(text: "Hello", keyword: "hello world", fz: 0.5, score: 0.291818181818182), + TestCase(text: "Hello", keyword: "hello wor1", fz: 0.5, score: 0.317142857142857), + TestCase(text: "Hello", keyword: "h", fz: 0.5, score: 0.57), + TestCase(text: "Hello", keyword: "H", fz: 0.5, score: 0.63), + TestCase(text: "Hello", keyword: "HiMi", fz: 0.5, score: 0.222), + TestCase(text: "Hello", keyword: "Hills", fz: 0.5, score: 0.33), + TestCase(text: "Hello", keyword: "Hillsd", fz: 0.5, score: 0.282), + TestCase(text: "Hillsdale Michigan", keyword: "axl", fz: 0.5, score: 0.12962962962963), + TestCase(text: "Hillsdale Michigan", keyword: "ow", fz: 0.5, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "e", fz: 0.5, score: 0.105555555555556), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 0.5, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "he", fz: 0.5, score: 0.4), + TestCase(text: "Hillsdale Michigan", keyword: "hel", fz: 0.5, score: 0.266666666666667), + TestCase(text: "Hillsdale Michigan", keyword: "hell", fz: 0.5, score: 0.21875), + TestCase(text: "Hillsdale Michigan", keyword: "hello", fz: 0.5, score: 0.196), + TestCase(text: "Hillsdale Michigan", keyword: "hello worl", fz: 0.5, score: 0.179382716049383), + TestCase(text: "Hillsdale Michigan", keyword: "hello world", fz: 0.5, score: 0.17489898989899), + TestCase(text: "Hillsdale Michigan", keyword: "hello wor1", fz: 0.5, score: 0.179382716049383), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 0.5, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "H", fz: 0.5, score: 0.572222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "HiMi", fz: 0.5, score: 0.669444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "Hills", fz: 0.5, score: 0.661111111111111), + TestCase(text: "Hillsdale Michigan", keyword: "Hillsd", fz: 0.5, score: 0.683333333333333), + TestCase(text: "hello world", keyword: "axl", fz: 0.7, score: 0.0265151515151515), + TestCase(text: "hello world", keyword: "ow", fz: 0.7, score: 0.354545454545455), + TestCase(text: "hello world", keyword: "e", fz: 0.7, score: 0.109090909090909), + TestCase(text: "hello world", keyword: "h", fz: 0.7, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "he", fz: 0.7, score: 0.622727272727273), + TestCase(text: "hello world", keyword: "hel", fz: 0.7, score: 0.659090909090909), + TestCase(text: "hello world", keyword: "hell", fz: 0.7, score: 0.695454545454545), + TestCase(text: "hello world", keyword: "hello", fz: 0.7, score: 0.731818181818182), + TestCase(text: "hello world", keyword: "hello worl", fz: 0.7, score: 0.913636363636364), + TestCase(text: "hello world", keyword: "hello world", fz: 0.7, score: 1.0), + TestCase(text: "hello world", keyword: "hello wor1", fz: 0.7, score: 0.678671328671329), + TestCase(text: "hello world", keyword: "h", fz: 0.7, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "H", fz: 0.7, score: 0.531818181818182), + TestCase(text: "hello world", keyword: "HiMi", fz: 0.7, score: 0.212799043062201), + TestCase(text: "hello world", keyword: "Hills", fz: 0.7, score: 0.304545454545455), + TestCase(text: "hello world", keyword: "Hillsd", fz: 0.7, score: 0.302935606060606), + TestCase(text: "He", keyword: "axl", fz: 0.7, score: 0.0), + TestCase(text: "He", keyword: "ow", fz: 0.7, score: 0.0), + TestCase(text: "He", keyword: "e", fz: 0.7, score: 0.15), + TestCase(text: "He", keyword: "h", fz: 0.7, score: 0.675), + TestCase(text: "He", keyword: "he", fz: 0.7, score: 0.9), + TestCase(text: "He", keyword: "hel", fz: 0.7, score: 0.630769230769231), + TestCase(text: "He", keyword: "hell", fz: 0.7, score: 0.5015625), + TestCase(text: "He", keyword: "hello", fz: 0.7, score: 0.426315789473684), + TestCase(text: "He", keyword: "hello worl", fz: 0.7, score: 0.282352941176471), + TestCase(text: "He", keyword: "hello world", fz: 0.7, score: 0.26977886977887), + TestCase(text: "He", keyword: "hello wor1", fz: 0.7, score: 0.282352941176471), + TestCase(text: "He", keyword: "h", fz: 0.7, score: 0.675), + TestCase(text: "He", keyword: "H", fz: 0.7, score: 0.75), + TestCase(text: "He", keyword: "HiMi", fz: 0.7, score: 0.307894736842105), + TestCase(text: "He", keyword: "Hills", fz: 0.7, score: 0.277272727272727), + TestCase(text: "He", keyword: "Hillsd", fz: 0.7, score: 0.256666666666667), + TestCase(text: "Hello", keyword: "axl", fz: 0.7, score: 0.0333333333333333), + TestCase(text: "Hello", keyword: "ow", fz: 0.7, score: 0.0538461538461538), + TestCase(text: "Hello", keyword: "e", fz: 0.7, score: 0.12), + TestCase(text: "Hello", keyword: "h", fz: 0.7, score: 0.57), + TestCase(text: "Hello", keyword: "he", fz: 0.7, score: 0.675), + TestCase(text: "Hello", keyword: "hel", fz: 0.7, score: 0.763333333333333), + TestCase(text: "Hello", keyword: "hell", fz: 0.7, score: 0.8475), + TestCase(text: "Hello", keyword: "hello", fz: 0.7, score: 0.93), + TestCase(text: "Hello", keyword: "hello worl", fz: 0.7, score: 0.384), + TestCase(text: "Hello", keyword: "hello world", fz: 0.7, score: 0.352597402597403), + TestCase(text: "Hello", keyword: "hello wor1", fz: 0.7, score: 0.384), + TestCase(text: "Hello", keyword: "h", fz: 0.7, score: 0.57), + TestCase(text: "Hello", keyword: "H", fz: 0.7, score: 0.63), + TestCase(text: "Hello", keyword: "HiMi", fz: 0.7, score: 0.244736842105263), + TestCase(text: "Hello", keyword: "Hills", fz: 0.7, score: 0.375), + TestCase(text: "Hello", keyword: "Hillsd", fz: 0.7, score: 0.323684210526316), + TestCase(text: "Hillsdale Michigan", keyword: "axl", fz: 0.7, score: 0.14957264957265), + TestCase(text: "Hillsdale Michigan", keyword: "ow", fz: 0.7, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "e", fz: 0.7, score: 0.105555555555556), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 0.7, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "he", fz: 0.7, score: 0.4), + TestCase(text: "Hillsdale Michigan", keyword: "hel", fz: 0.7, score: 0.284615384615385), + TestCase(text: "Hillsdale Michigan", keyword: "hell", fz: 0.7, score: 0.2359375), + TestCase(text: "Hillsdale Michigan", keyword: "hello", fz: 0.7, score: 0.210526315789474), + TestCase(text: "Hillsdale Michigan", keyword: "hello worl", fz: 0.7, score: 0.192652329749104), + TestCase(text: "Hillsdale Michigan", keyword: "hello world", fz: 0.7, score: 0.186616161616162), + TestCase(text: "Hillsdale Michigan", keyword: "hello wor1", fz: 0.7, score: 0.192652329749104), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 0.7, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "H", fz: 0.7, score: 0.572222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "HiMi", fz: 0.7, score: 0.669444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "Hills", fz: 0.7, score: 0.661111111111111), + TestCase(text: "Hillsdale Michigan", keyword: "Hillsd", fz: 0.7, score: 0.683333333333333), + TestCase(text: "hello world", keyword: "axl", fz: 1.0, score: 0.0424242424242424), + TestCase(text: "hello world", keyword: "ow", fz: 1.0, score: 0.354545454545455), + TestCase(text: "hello world", keyword: "e", fz: 1.0, score: 0.109090909090909), + TestCase(text: "hello world", keyword: "h", fz: 1.0, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "he", fz: 1.0, score: 0.622727272727273), + TestCase(text: "hello world", keyword: "hel", fz: 1.0, score: 0.659090909090909), + TestCase(text: "hello world", keyword: "hell", fz: 1.0, score: 0.695454545454545), + TestCase(text: "hello world", keyword: "hello", fz: 1.0, score: 0.731818181818182), + TestCase(text: "hello world", keyword: "hello worl", fz: 1.0, score: 0.913636363636364), + TestCase(text: "hello world", keyword: "hello world", fz: 1.0, score: 1.0), + TestCase(text: "hello world", keyword: "hello wor1", fz: 1.0, score: 0.837272727272727), + TestCase(text: "hello world", keyword: "h", fz: 1.0, score: 0.586363636363636), + TestCase(text: "hello world", keyword: "H", fz: 1.0, score: 0.531818181818182), + TestCase(text: "hello world", keyword: "HiMi", fz: 1.0, score: 0.269318181818182), + TestCase(text: "hello world", keyword: "Hills", fz: 1.0, score: 0.397272727272727), + TestCase(text: "hello world", keyword: "Hillsd", fz: 1.0, score: 0.39469696969697), + TestCase(text: "He", keyword: "axl", fz: 1.0, score: 0.0), + TestCase(text: "He", keyword: "ow", fz: 1.0, score: 0.0), + TestCase(text: "He", keyword: "e", fz: 1.0, score: 0.15), + TestCase(text: "He", keyword: "h", fz: 1.0, score: 0.675), + TestCase(text: "He", keyword: "he", fz: 1.0, score: 0.9), + TestCase(text: "He", keyword: "hel", fz: 1.0, score: 0.775), + TestCase(text: "He", keyword: "hell", fz: 1.0, score: 0.7125), + TestCase(text: "He", keyword: "hello", fz: 1.0, score: 0.675), + TestCase(text: "He", keyword: "hello worl", fz: 1.0, score: 0.6), + TestCase(text: "He", keyword: "hello world", fz: 1.0, score: 0.593181818181818), + TestCase(text: "He", keyword: "hello wor1", fz: 1.0, score: 0.6), + TestCase(text: "He", keyword: "h", fz: 1.0, score: 0.675), + TestCase(text: "He", keyword: "H", fz: 1.0, score: 0.75), + TestCase(text: "He", keyword: "HiMi", fz: 1.0, score: 0.45), + TestCase(text: "He", keyword: "Hills", fz: 1.0, score: 0.43), + TestCase(text: "He", keyword: "Hillsd", fz: 1.0, score: 0.416666666666667), + TestCase(text: "Hello", keyword: "axl", fz: 1.0, score: 0.0533333333333333), + TestCase(text: "Hello", keyword: "ow", fz: 1.0, score: 0.07), + TestCase(text: "Hello", keyword: "e", fz: 1.0, score: 0.12), + TestCase(text: "Hello", keyword: "h", fz: 1.0, score: 0.57), + TestCase(text: "Hello", keyword: "he", fz: 1.0, score: 0.675), + TestCase(text: "Hello", keyword: "hel", fz: 1.0, score: 0.763333333333333), + TestCase(text: "Hello", keyword: "hell", fz: 1.0, score: 0.8475), + TestCase(text: "Hello", keyword: "hello", fz: 1.0, score: 0.93), + TestCase(text: "Hello", keyword: "hello worl", fz: 1.0, score: 0.735), + TestCase(text: "Hello", keyword: "hello world", fz: 1.0, score: 0.717272727272727), + TestCase(text: "Hello", keyword: "hello wor1", fz: 1.0, score: 0.735), + TestCase(text: "Hello", keyword: "h", fz: 1.0, score: 0.57), + TestCase(text: "Hello", keyword: "H", fz: 1.0, score: 0.63), + TestCase(text: "Hello", keyword: "HiMi", fz: 1.0, score: 0.33), + TestCase(text: "Hello", keyword: "Hills", fz: 1.0, score: 0.51), + TestCase(text: "Hello", keyword: "Hillsd", fz: 1.0, score: 0.48), + TestCase(text: "Hillsdale Michigan", keyword: "axl", fz: 1.0, score: 0.194444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "ow", fz: 1.0, score: 0.0), + TestCase(text: "Hillsdale Michigan", keyword: "e", fz: 1.0, score: 0.105555555555556), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 1.0, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "he", fz: 1.0, score: 0.4), + TestCase(text: "Hillsdale Michigan", keyword: "hel", fz: 1.0, score: 0.325), + TestCase(text: "Hillsdale Michigan", keyword: "hell", fz: 1.0, score: 0.2875), + TestCase(text: "Hillsdale Michigan", keyword: "hello", fz: 1.0, score: 0.265), + TestCase(text: "Hillsdale Michigan", keyword: "hello worl", fz: 1.0, score: 0.282222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "hello world", fz: 1.0, score: 0.274494949494949), + TestCase(text: "Hillsdale Michigan", keyword: "hello wor1", fz: 1.0, score: 0.282222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "h", fz: 1.0, score: 0.519444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "H", fz: 1.0, score: 0.572222222222222), + TestCase(text: "Hillsdale Michigan", keyword: "HiMi", fz: 1.0, score: 0.669444444444444), + TestCase(text: "Hillsdale Michigan", keyword: "Hills", fz: 1.0, score: 0.661111111111111), + TestCase(text: "Hillsdale Michigan", keyword: "Hillsd", fz: 1.0, score: 0.683333333333333), + ] + + static var diacritics: [TestCase] = [ + TestCase(text: "lIIIIIII", keyword: "l", fz: 0.0, score: 0.6), + TestCase(text: "lIIIIIII", keyword: "l", fz: 0.5, score: 0.6), + TestCase(text: "lIIIIIII", keyword: "l", fz: 1.0, score: 0.6), + TestCase(text: "lIIIIIII", keyword: "i", fz: 0.0, score: 0.05625), + TestCase(text: "lIIIIIII", keyword: "i", fz: 0.5, score: 0.05625), + TestCase(text: "lIIIIIII", keyword: "i", fz: 1.0, score: 0.05625), + TestCase(text: "lIIIIIII", keyword: "L", fz: 0.0, score: 0.54375), + TestCase(text: "lIIIIIII", keyword: "L", fz: 0.5, score: 0.54375), + TestCase(text: "lIIIIIII", keyword: "L", fz: 1.0, score: 0.54375), + TestCase(text: "lIIIIIII", keyword: "I", fz: 0.0, score: 0.1125), + TestCase(text: "lIIIIIII", keyword: "I", fz: 0.5, score: 0.1125), + TestCase(text: "lIIIIIII", keyword: "I", fz: 1.0, score: 0.1125), + TestCase(text: "lIIIIIII", keyword: "İ", fz: 0.0, score: 0.05625), + TestCase(text: "lIIIIIII", keyword: "İ", fz: 0.5, score: 0.05625), + TestCase(text: "lIIIIIII", keyword: "İ", fz: 1.0, score: 0.05625), + + TestCase(text: "lİİİİİİİ", keyword: "l", fz: 0.0, score: 0.6), + TestCase(text: "lİİİİİİİ", keyword: "l", fz: 0.5, score: 0.6), + TestCase(text: "lİİİİİİİ", keyword: "l", fz: 1.0, score: 0.6), + TestCase(text: "lİİİİİİİ", keyword: "i", fz: 0.0, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "i", fz: 0.5, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "i", fz: 1.0, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "L", fz: 0.0, score: 0.54375), + TestCase(text: "lİİİİİİİ", keyword: "L", fz: 0.5, score: 0.54375), + TestCase(text: "lİİİİİİİ", keyword: "L", fz: 1.0, score: 0.54375), + TestCase(text: "lİİİİİİİ", keyword: "I", fz: 0.0, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "I", fz: 0.5, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "I", fz: 1.0, score: 0.05625), + TestCase(text: "lİİİİİİİ", keyword: "İ", fz: 0.0, score: 0.1125), + TestCase(text: "lİİİİİİİ", keyword: "İ", fz: 0.5, score: 0.1125), + TestCase(text: "lİİİİİİİ", keyword: "İ", fz: 1.0, score: 0.1125), + + TestCase(text: "lİİİİIII", keyword: "l", fz: 0.0, score: 0.6), + TestCase(text: "lİİİİIII", keyword: "l", fz: 0.5, score: 0.6), + TestCase(text: "lİİİİIII", keyword: "l", fz: 1.0, score: 0.6), + TestCase(text: "lİİİİIII", keyword: "i", fz: 0.0, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "i", fz: 0.5, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "i", fz: 1.0, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "L", fz: 0.0, score: 0.54375), + TestCase(text: "lİİİİIII", keyword: "L", fz: 0.5, score: 0.54375), + TestCase(text: "lİİİİIII", keyword: "L", fz: 1.0, score: 0.54375), + TestCase(text: "lİİİİIII", keyword: "I", fz: 0.0, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "I", fz: 0.5, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "I", fz: 1.0, score: 0.05625), + TestCase(text: "lİİİİIII", keyword: "İ", fz: 0.0, score: 0.1125), + TestCase(text: "lİİİİIII", keyword: "İ", fz: 0.5, score: 0.1125), + TestCase(text: "lİİİİIII", keyword: "İ", fz: 1.0, score: 0.1125), + + TestCase(text: "štediti područje", keyword: "sp", fz: 0.0, score: 0.628125), + TestCase(text: "štediti područje", keyword: "sp", fz: 0.5, score: 0.628125), + TestCase(text: "štediti područje", keyword: "sp", fz: 1.0, score: 0.628125), + TestCase(text: "štediti područje", keyword: "st", fz: 0.0, score: 0.571875), + TestCase(text: "štediti područje", keyword: "st", fz: 0.5, score: 0.571875), + TestCase(text: "štediti područje", keyword: "st", fz: 1.0, score: 0.571875), + TestCase(text: "štediti područje", keyword: "pod", fz: 0.0, score: 0.514583333333333), + TestCase(text: "štediti područje", keyword: "pod", fz: 0.5, score: 0.514583333333333), + TestCase(text: "štediti područje", keyword: "pod", fz: 1.0, score: 0.514583333333333), + + TestCase(text: "stediti podrucje", keyword: "sp", fz: 0.0, score: 0.65625), + TestCase(text: "stediti podrucje", keyword: "sp", fz: 0.5, score: 0.65625), + TestCase(text: "stediti podrucje", keyword: "sp", fz: 1.0, score: 0.65625), + TestCase(text: "stediti podrucje", keyword: "st", fz: 0.0, score: 0.6), + TestCase(text: "stediti podrucje", keyword: "st", fz: 0.5, score: 0.6), + TestCase(text: "stediti podrucje", keyword: "st", fz: 1.0, score: 0.6), + TestCase(text: "stediti podrucje", keyword: "pod", fz: 0.0, score: 0.514583333333333), + TestCase(text: "stediti podrucje", keyword: "pod", fz: 0.5, score: 0.514583333333333), + TestCase(text: "stediti podrucje", keyword: "pod", fz: 1.0, score: 0.514583333333333), + ] }