SPB Git

Repository Public MIT

GlassProgressTests.swift 3.6 KB 89 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Tests/SPGlassComponentsTests/GlassProgressTests.swift8// Module           : Tests9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import Testing43@testable import SPGlassComponents4445@Suite("GlassProgress")46struct GlassProgressTests {47    @Test func fractionIsValueOverTotal() {48        #expect(GlassProgressMath.fraction(value: 0.25) == 0.25)49        #expect(GlassProgressMath.fraction(value: 30, total: 120) == 0.25)50        #expect(GlassProgressMath.fraction(value: 120, total: 120) == 1)51    }5253    @Test func fractionIsClampedToZeroAndOne() {54        #expect(GlassProgressMath.fraction(value: -3, total: 10) == 0)55        #expect(GlassProgressMath.fraction(value: 25, total: 10) == 1)56    }5758    @Test func invalidInputsGiveZero() {59        #expect(GlassProgressMath.fraction(value: 5, total: 0) == 0)60        #expect(GlassProgressMath.fraction(value: 5, total: -10) == 0)61        #expect(GlassProgressMath.fraction(value: .nan, total: 10) == 0)62        #expect(GlassProgressMath.fraction(value: 5, total: .nan) == 0)63        #expect(GlassProgressMath.fraction(value: .infinity, total: 10) == 0)64        #expect(GlassProgressMath.fraction(value: 5, total: .infinity) == 0)65    }6667    @Test func percentIsRoundedToAWholeNumber() {68        #expect(GlassProgressMath.percent(0) == 0)69        #expect(GlassProgressMath.percent(0.424) == 42)70        #expect(GlassProgressMath.percent(0.425) == 43)71        #expect(GlassProgressMath.percent(0.999) == 100)72        #expect(GlassProgressMath.percent(7) == 100)73        #expect(GlassProgressMath.percent(-1) == 0)74    }7576    @Test func percentTextFollowsTheLocale() {77        #expect(GlassProgressMath.percentText(0.42, locale: Locale(identifier: "en_US")) == "42%")78        let french = GlassProgressMath.percentText(0.42, locale: Locale(identifier: "fr_FR"))79        #expect(french.hasPrefix("42"))80        #expect(french.hasSuffix("%"))81        #expect(french != "42%")82        #expect(GlassProgressMath.percentText(3, locale: Locale(identifier: "en_US")) == "100%")83    }8485    @Test func twoStylesAreOffered() {86        #expect(GlassProgressStyle.allCases == [.linear, .circular])87    }88}89
Files main
Menu

Theme