Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Nov 3, 2022
1 parent 810bd50 commit b528d12
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 50 deletions.
6 changes: 0 additions & 6 deletions Tests/DemoState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import Foundation
import Verge
import XCTest

extension XCTestCase {
func vergeMeasure(perform: () -> Void) {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()], block: perform)
}
}

struct NonEquatable: Sendable {
let id = UUID()
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/VergeClassicTests/VergeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class VergeTests: XCTestCase {

func testPerformanceExample() {
// This is an example of a performance test case.
self.vergeMeasure {
self.measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
// Put the code you want to measure the time of here.
}
}
Expand All @@ -130,7 +130,7 @@ class VergeTests: XCTestCase {

let vm = ViewModel()

self.vergeMeasure {
self.measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
vm.increment()
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/VergeORMTests/CollectionPerformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import XCTest
class CollectionPerformance: XCTestCase {

func testMakeCollection() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = AnyCollection((0..<100000).map { $0 })
}
}

func testMakeLazySequence() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = (0..<100000).lazy.map { $0 }
}
}

func testMakeLazyCollection() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = AnyCollection((0..<100000).lazy.map { $0 })
}
}
Expand All @@ -34,7 +34,7 @@ class CollectionPerformance: XCTestCase {

let a = (0..<10000).map { Int($0) }

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = a as [Any]
}

Expand All @@ -46,7 +46,7 @@ class CollectionPerformance: XCTestCase {
d[n] = n
}

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = a as [Int : Any]
}

Expand All @@ -58,7 +58,7 @@ class CollectionPerformance: XCTestCase {
d[n] = n
}

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = a as! [Int : Int]
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/VergeORMTests/EntityDerivedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ final class DerivedTests: XCTestCase {

let storage = Store<RootState, Never>.init(initialState: .init(), logger: nil)

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
let _ = storage.databases.db.derived(from: Author.EntityID("Hoo"), queue: .passthrough)
}

Expand All @@ -265,7 +265,7 @@ final class DerivedTests: XCTestCase {

let _ = storage.databases.db.derived(from: Author.EntityID("Hoo"), queue: .passthrough)

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
let _ = storage.databases.db.derived(from: Author.EntityID("Hoo"), queue: .passthrough)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/VergeORMTests/MultithreadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MultithreadingTests: XCTestCase {

let store = Storage(RootState())

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
DispatchQueue.concurrentPerform(iterations: 1000) { (i) in
store.update { state in
state.other.count += 1
Expand Down
28 changes: 14 additions & 14 deletions Tests/VergeORMTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ final class PerformanceTests: XCTestCase {
var state = RootState()

func testReflectionObjectIdentifier() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = ObjectIdentifier(Author.self)
}
}

func testReflectionString() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = String(reflecting: Author.self)
}
}
Expand All @@ -37,7 +37,7 @@ final class PerformanceTests: XCTestCase {
context.entities.author.insert(authors)
}

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { context in
var author = context.entities.author.current.find(by: .init("author.100"))!
author.name = "mmm"
Expand All @@ -57,7 +57,7 @@ final class PerformanceTests: XCTestCase {
context.entities.author.insert(authors)
}

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { context -> Void in
context.entities.author.updateIfExists(id: .init("author.100")) { (author) in
author.name = "mmm"
Expand All @@ -69,7 +69,7 @@ final class PerformanceTests: XCTestCase {

func testInsertMany() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

let authors = (0..<10000).map { i in Author(rawID: "author.\(i)") }
Expand All @@ -82,7 +82,7 @@ final class PerformanceTests: XCTestCase {

func testInsert3000() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

for i in 0..<3000 {
Expand All @@ -97,7 +97,7 @@ final class PerformanceTests: XCTestCase {

func testInsert3000UseCollection() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

let authors = (0..<3000).map { i in
Expand All @@ -113,7 +113,7 @@ final class PerformanceTests: XCTestCase {

func testInsert10000UseCollection() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

let authors = (0..<10000).map { i in
Expand All @@ -129,7 +129,7 @@ final class PerformanceTests: XCTestCase {

func testInsert100000UseCollection() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

let authors = (0..<100000).map { i in
Expand All @@ -153,7 +153,7 @@ final class PerformanceTests: XCTestCase {
context.entities.author.insert(authors)
}

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
state.db.performBatchUpdates { (context) in

let authors = (0..<1000).map { i in
Expand All @@ -169,7 +169,7 @@ final class PerformanceTests: XCTestCase {

func testInsertSoManySeparatedTransaction() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for l in 0..<10 {
state.db.performBatchUpdates { (context) in

Expand All @@ -185,7 +185,7 @@ final class PerformanceTests: XCTestCase {
}

func testInsertManyEachTransaction() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
/// O(n^2)
for i in 0..<10 {
state.db.performBatchUpdates { (context) in
Expand Down Expand Up @@ -217,7 +217,7 @@ final class FindPerformanceTests: XCTestCase {

func testFindOne() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = state.db.entities.author.find(by: .init("author.199"))
}

Expand All @@ -231,7 +231,7 @@ final class FindPerformanceTests: XCTestCase {
.init("author.399"),
])

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = state.db.entities.author.find(in: ids)
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/VergeORMTests/ReflectingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ReflectingTests: XCTestCase {

func testGettingTypeName_typeof() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<10000 {
_ = type(of: A.B.A.self)
}
Expand All @@ -29,7 +29,7 @@ class ReflectingTests: XCTestCase {

func testGettingTypeName_typeName_metatype() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<10000 {
_ = _typeName(type(of: A.B.A.self))
}
Expand All @@ -38,7 +38,7 @@ class ReflectingTests: XCTestCase {

func testGettingTypeName_string_reflecting_metatype() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<10000 {
_ = String(reflecting: type(of: A.B.A.self))
}
Expand All @@ -47,7 +47,7 @@ class ReflectingTests: XCTestCase {

func testGettingTypeName_string_reflecting() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<10000 {
_ = String(reflecting: A.B.A.self)
}
Expand All @@ -56,7 +56,7 @@ class ReflectingTests: XCTestCase {

func testObjectIdentifier_string_reflecting() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<10000 {
_ = ObjectIdentifier(A.B.A.self)
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/VergeORMTests/SetIndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class SetIndexTests: XCTestCase {
}()

func testSample() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = db.indexes.allBooks.map { $0.raw }
}
}

func testCompactMap() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = db.indexes.allBooks.compactMap { $0.raw }
}
}

func testFilter() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = db.indexes.allBooks.sorted { $0.raw > $1.raw }
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/VergeTests/ComputedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Computed2Tests: XCTestCase {

let changes = store.state

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = changes.computed.filteredArray
}

Expand All @@ -142,7 +142,7 @@ class Computed2Tests: XCTestCase {

let store = MyStore()

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
store.commit {
// no affects to array
$0.num_1 += 1
Expand Down Expand Up @@ -293,7 +293,7 @@ class Computed2Tests: XCTestCase {

let changes = store.state

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
DispatchQueue.concurrentPerform(iterations: 500) { (i) in
XCTAssertEqual(changes.hasChanges(\.computed.num_0), false)
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/VergeTests/CopyPerformance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ final class CopyPerformance: XCTestCase {

func testCopy() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
run(with: source)
}
}

func testCopyWithShared() {

let huge = Shared(source)
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
run(with: huge)
}
}

func testAny() {
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
run(any: source)
}
}

func testAnyWithShared() {
let huge = Shared(source)
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
run(anyObject: huge)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/VergeTests/CounterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ final class CounterTests: XCTestCase {

func testGenDatePerformance() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = Date()
}
}

func testGenCFDatePerformance() {

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
_ = CFAbsoluteTimeGetCurrent()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/VergeTests/EventEmitterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class EventEmitterTests: XCTestCase {
func testRegistrationPerformance() {

let emitter = EventEmitter<Void>()
vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
for _ in 0..<1000 {
emitter.add { _ in

Expand Down
2 changes: 1 addition & 1 deletion Tests/VergeTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PerformanceTests: XCTestCase {

let store = DemoStore()

vergeMeasure {
measure(metrics: [XCTMemoryMetric(), XCTCPUMetric(), XCTClockMetric()]) {
store.increment()
}

Expand Down

0 comments on commit b528d12

Please sign in to comment.