Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Sheet9// File : Packages/SheetIntelligence/Tests/SheetIntelligenceTests/Support.swift10// Module : SheetIntelligenceTests11// Repository : https://git.spboucher.ai/orix-sheet12// Created : 2026-11-2113// Last Modified : 2026-11-2114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author : Simon-Pierre Boucher20// Position : Professor of Finance21// Institution : Université du Québec en Outaouais (UQO)22// Department : Département des sciences administratives23// Organization : SP Boucher24//25// Website : https://spboucher.ai26// Git : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General : info@spboucher.ai33// Professional : contact@spboucher.ai34// Direct : simon@spboucher.ai35// Research : research@spboucher.ai36// Development : dev@spboucher.ai37// Support : support@spboucher.ai38// Security/Admin : admin@spboucher.ai39// Notifications : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification : Public66// Distribution : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License : None specified (no license file in this repository)80// Maintainer : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import Foundation88import SheetCore89import FunctionsNumeric90import FunctionsText91import FunctionsLookup92@testable import SheetIntelligence9394/// Registers the function libraries the app registers at launch (once per process).95enum Fixtures {96 static let registered: Bool = {97 NumericFunctions.register()98 TextFunctions.register()99 LookupFunctions.register()100 FinancialFunctions.register()101 return true102 }()103104 static let regions = ["North", "South", "East", "West"]105 static let products = ["Widget", "Gadget", "Gizmo"]106107 /// Synthetic sales table: A Region, B Product, C Units, D Unit Price, E Revenue (=C*D), F Date; rows 2…21.108 /// Second sheet "Params" with a tax rate (defined name TaxRate) and a small lookup table.109 static func sales() -> (workbook: Workbook, engine: CalcEngine) {110 _ = registered111 let wb = Workbook(sheetNames: ["Sales", "Params"])112 let engine = CalcEngine(workbook: wb)113 let parser = InputParser(locale: Locale(identifier: "en_US"))114 func put(_ sheet: Int, _ a1: String, _ text: String) {115 let c = CellRef(a1: a1)!116 try! engine.setInput(sheet: sheet, row: c.row, col: c.col, text, parser: parser)117 }118 for (k, h) in ["Region", "Product", "Units", "Unit Price", "Revenue", "Date"].enumerated() { put(0, "\(A1.columnName(k))1", h) }119 for i in 0..<20 {120 let row = i + 2121 put(0, "A\(row)", regions[i % 4])122 put(0, "B\(row)", products[i % 3])123 put(0, "C\(row)", String(units(i)))124 put(0, "D\(row)", String(price(i)))125 put(0, "E\(row)", "=C\(row)*D\(row)")126 put(0, "F\(row)", String(format: "2026-%02d-%02d", i / 7 + 1, (i * 3) % 27 + 1))127 }128 put(1, "A1", "Tax rate"); put(1, "B1", "0.15")129 put(1, "A3", "Product"); put(1, "B3", "Cost")130 for (k, p) in products.enumerated() { put(1, "A\(4 + k)", p); put(1, "B\(4 + k)", String([4.0, 7.5, 11.0][k])) }131 wb.setDefinedName(DefinedName(name: "TaxRate", formula: "Params!$B$1"))132 engine.rebuildGraph()133 _ = engine.recalculate()134 return (wb, engine)135 }136137 static func units(_ i: Int) -> Int { 5 + (i * 7) % 23 }138 static func price(_ i: Int) -> Double { [9.5, 14.0, 22.25][i % 3] }139 static func revenue(_ i: Int) -> Double { Double(units(i)) * price(i) }140141 static func context(active: String = "H2", selection: String? = nil, limits: ContextLimits = ContextLimits()) -> SheetContext {142 let (wb, _) = sales()143 let a = CellRef(a1: active)!144 return ContextBuilder.sheetContext(workbook: wb, sheet: 0, selection: selection.flatMap { RangeRef(a1: $0) } ?? RangeRef(a), active: a, limits: limits)145 }146147 static func profile() -> TableProfile {148 let (wb, _) = sales()149 return ContextBuilder.tableProfile(workbook: wb, sheet: 0, range: RangeRef(a1: "A1:F21")!)150 }151}152