Skip to content

Commit

Permalink
added generic test
Browse files Browse the repository at this point in the history
  • Loading branch information
roznet committed Dec 23, 2020
1 parent 340d30c commit 4e0f975
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
32 changes: 31 additions & 1 deletion Sources/FitFileParser/FitFieldValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,39 @@ import CoreLocation

public typealias FitDoubleUnit = (value:Double,unit:String)

func optionalsAreEqual<T: Comparable>(_ firstVal: T?, _ secondVal: T?) -> Bool{

if let firstVal = firstVal, let secondVal = secondVal {
return firstVal == secondVal
}
else{
return firstVal == nil && secondVal == nil
}
}

/// An object to contain fit value with a single swift type no matter what the underlying type is
public class FitFieldValue {
public class FitFieldValue : Equatable{

public static func == (lhs: FitFieldValue, rhs: FitFieldValue) -> Bool {
if lhs.type == rhs.type && lhs.developer == rhs.developer{
switch lhs.type {
case .coordinate:
return optionalsAreEqual(lhs.coordinate?.latitude, rhs.coordinate?.latitude) && optionalsAreEqual(lhs.coordinate?.longitude, rhs.coordinate?.longitude)
case .time:
return optionalsAreEqual(lhs.time, rhs.time)
case .value:
return optionalsAreEqual(lhs.value, rhs.value)
case .valueUnit:
return optionalsAreEqual(lhs.valueUnit?.value, rhs.valueUnit?.value) && optionalsAreEqual(lhs.valueUnit?.unit, rhs.valueUnit?.unit)
case .name:
return optionalsAreEqual(lhs.name, rhs.name)
case .invalid:
return true
}
}
return false
}

public enum ValueType {
case coordinate, time, value, valueUnit, name, invalid
}
Expand Down
12 changes: 8 additions & 4 deletions Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ final class FitFileParserSwiftTests: XCTestCase {

let fit_generic = FitFile(data: data, parsingType: FitFile.ParsingType.generic)
XCTAssertTrue(fit_generic.hasMessageType(messageType: FIT_MESG_NUM_SESSION))
/*
let session_fast = fit_fast.messages(forMessageType: FIT_MESG_NUM_SESSION)
let session_generic = fit_fast.messages(forMessageType: FIT_MESG_NUM_SESSION)

print("\(session_fast) \(session_generic)")*/
let session_fast = fit_fast.messages(forMessageType: FIT_MESG_NUM_SESSION).first?.interpretedFields()
let session_generic = fit_fast.messages(forMessageType: FIT_MESG_NUM_SESSION).first?.interpretedFields()
XCTAssertNotNil(session_fast)
XCTAssertNotNil(session_generic)
if let session_fast = session_fast, let session_generic = session_generic{
XCTAssertEqual(session_fast.count, session_generic.count)
XCTAssertEqual(session_fast, session_generic)
}
}
}

Expand Down

0 comments on commit 4e0f975

Please sign in to comment.