Skip to content

Adds support for Base-"|||| |||| ||" #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public struct DecimalNumber: PositionalNumberSystemizable {
public enum Digit: Int {
case zero
case one, two , three, four, five
case six, seven, eight, nine, ten
}
}

extension DecimalNumber.Digit: PositionalDigitSystemizable {
public static var placeholder: Self { .zero }

public var predecessor: Self {
switch self {
case .ten : return .nine
case .nine : return .eight
case .eight: return .seven
case .seven: return .six
case .six : return .five
case .five : return .four
case .four : return .three
case .three: return .two
case .two : return .one
case .one : return .placeholder
default : Self.fatalPredecessionError()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
public protocol PositionalDigitSystemizable: CaseIterable, RawRepresentable<Int> {
static var placeholder: Self { get }

var predecessor: Self { get }
}

extension PositionalDigitSystemizable {
public static func fatalPredecessionError() -> Never {
fatalError("Digit has no defined precedent")
}

public var quantity: Quantity {
if self == Self.placeholder { return Quantity.none }

let precedingQuantity = self.predecessor.quantity
return precedingQuantity.successor
}
}

extension PositionalDigitSystemizable {
public var cardinality: Int {
self.rawValue
}

public var quantityMatchesCardinality: Bool {
self.cardinality.represents(self.quantity)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
protocol PositionalNumberSystemizable {
associatedtype Digit: PositionalDigitSystemizable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Testing
@testable import NumberSystems

@Test func quantitiesOfDecimalDigits() async throws {
DecimalNumber.Digit.allCases.forEach {
#expect($0.quantityMatchesCardinality)
}
}