Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
NeedleInAJayStack committed May 26, 2024
1 parent 173f8a7 commit 2bfa069
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions Sources/Units/Registry.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// UnitRegistry defines a structure that contains all defined units. This ensures
/// that we are able to parse to and from unit symbol representations.
internal class Registry {
class Registry {
// TODO: Should we eliminate this singleton and make clients keep track?
internal static let instance = Registry()
static let instance = Registry()

// Quick access based on symbol
private var symbolMap: [String: DefinedUnit]
Expand All @@ -29,7 +29,7 @@ internal class Registry {

/// Returns a list of defined units and their exponents, given a composite unit symbol. It is expected that the caller has
/// verified that this is a composite unit.
internal func compositeUnitsFromSymbol(symbol: String) throws -> [DefinedUnit: Int] {
func compositeUnitsFromSymbol(symbol: String) throws -> [DefinedUnit: Int] {
let symbolsAndExponents = try deserializeSymbolicEquation(symbol)

var compositeUnits = [DefinedUnit: Int]()
Expand All @@ -45,7 +45,7 @@ internal class Registry {

/// Returns a defined unit given a defined unit symbol. It is expected that the caller has
/// verified that this is not a composite unit.
internal func getUnit(bySymbol symbol: String) throws -> DefinedUnit {
func getUnit(bySymbol symbol: String) throws -> DefinedUnit {
guard let definedUnit = symbolMap[symbol] else {
throw UnitError.unitNotFound(message: "Symbol '\(symbol)' not recognized")
}
Expand All @@ -54,7 +54,7 @@ internal class Registry {

/// Returns a defined unit given a defined unit name. It is expected that the caller has
/// verified that this is not a composite unit.
internal func getUnit(byName name: String) throws -> DefinedUnit {
func getUnit(byName name: String) throws -> DefinedUnit {
guard let definedUnit = nameMap[name] else {
throw UnitError.unitNotFound(message: "Name '\(name)' not recognized")
}
Expand All @@ -67,7 +67,7 @@ internal class Registry {
/// - parameter dimension: The unit dimensionality as a dictionary of quantities and their respective exponents.
/// - parameter coefficient: The value to multiply a base unit of this dimension when converting it to this unit. For base units, this is 1.
/// - parameter constant: The value to add to a base unit when converting it to this unit. This is added after the coefficient is multiplied according to order-of-operations.
internal func addUnit(
func addUnit(
name: String,
symbol: String,
dimension: [Quantity: Int],
Expand Down Expand Up @@ -95,7 +95,7 @@ internal class Registry {
}

/// Returns all units currently defined by the registry
internal func allUnits() -> [Unit] {
func allUnits() -> [Unit] {
var allUnits = [Unit]()
for (_, unit) in symbolMap {
allUnits.append(Unit(definedBy: unit))
Expand Down
4 changes: 2 additions & 2 deletions Sources/Units/Unit/Unit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public struct Unit {

/// Create a unit from the defined unit object.
/// - Parameter definedBy: A defined unit to wrap
internal init(definedBy: DefinedUnit) {
init(definedBy: DefinedUnit) {
type = .defined(definedBy)
}

/// Create a new from the sub-unit dictionary.
/// - Parameter subUnits: A dictionary of defined units and exponents. If this dictionary has only a single unit with an exponent of one,
/// we return that defined unit directly.
internal init(composedOf subUnits: [DefinedUnit: Int]) {
init(composedOf subUnits: [DefinedUnit: Int]) {
if subUnits.count == 1, let subUnit = subUnits.first, subUnit.value == 1 {
type = .defined(subUnit.key)
} else {
Expand Down
1 change: 1 addition & 0 deletions Tests/UnitsTests/XCTest+Measurement.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Units

// import Foundation
import XCTest

Expand Down

0 comments on commit 2bfa069

Please sign in to comment.