Skip to content
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

完成内存缓存 #27

Merged
merged 5 commits into from
Jul 29, 2019
Merged
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
1 change: 1 addition & 0 deletions ClaretCacheDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.ClaretCache.-";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG ClaretCacheLOG";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
3 changes: 0 additions & 3 deletions ClaretCacheDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
Expand Down Expand Up @@ -41,6 +40,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

2 changes: 0 additions & 2 deletions ClaretCacheDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ class ViewController: UIViewController {
// Do any additional setup after loading the view.
}


}

42 changes: 37 additions & 5 deletions ClaretCacheDemoTests/ClaretCacheDemoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,59 @@
//

import XCTest
@testable import ClaretCacheDemo

class ClaretCacheDemoTests: XCTestCase {

let cache: MemoryCache<Int, Int> = MemoryCache<Int, Int>()

override func setUp() {
// Put setup code here. This method is called before the invocation of each test method in the class.
// self.cache = MemoryCache<String, Int>()
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() {
func testInsert() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
self.cache.countLimit = 800

for idx in 1...1000 {
self.cache[idx] = idx
}

assert(self.cache.totalCount == 800, "淘汰策略出错")
}

func testPerformanceExample() {
// This is an example of a performance test case.
measure(metrics: [XCTCPUMetric()]) {
// Put the code whose CPU performance you want to measure here.
func testRead() {
self.cache.removeAll()

self.cache.countLimit = 800

for idx in 1...1000 {
self.cache[idx] = idx
}
// print("key: 1, value: \(self.cache[1] ?? -1)")
// print("key: 888, value: \(self.cache[888] ?? -1)")
// print("key: 777, value: \(self.cache[777] ?? -1)")
// print("key: 999, value: \(self.cache[999] ?? -1)")
assert(self.cache[1] == nil, "淘汰策略出错")
assert((self.cache[888] ?? -1) == 888, "读取key为888,失败")
assert((self.cache[777] ?? -1) == 777, "读取key为777,失败")
assert((self.cache[999] ?? -1) == 999, "读取key为999,失败")
}

// func testPerformanceExample() {
// // This is an example of a performance test case.
// measure(metrics: [XCTCPUMetric()]) {
// // Put the code whose CPU performance you want to measure here.
// for idx in 1...100_000 {
// self.cache[idx] = idx
// }
// }
// }

}
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "ClaretCache",
targets: ["ClaretCache"]),
targets: ["ClaretCache"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -23,6 +23,6 @@ let package = Package(
dependencies: []),
.testTarget(
name: "ClaretCacheTests",
dependencies: ["ClaretCache"]),
dependencies: ["ClaretCache"])
]
)
Loading