<commit_before>
// https://github.com/pixel-ink/PIImageCache

import UIKit
import XCTest

class PIImageMemoryCacheTests: XCTestCase {
  
  func testDownload() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    let (image,dataSize) = cache.download(url)!
    XCTAssert(dataSize == 926 , "Pass")
    XCTAssert(image.size.width == 200 && image.size.height == 200 , "Pass")
  }
  
  func testPerform() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    var image: UIImage?, result: PIImageCache.Result
    (image, result) = cache.perform(url)
    XCTAssert(result != .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    (image, result) = cache.perform(url)
    XCTAssert(result == .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
  }
  
  func testCacheLimit() {
    let cache = PIImageCache()
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 15 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 10 ..< 15 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 10 ..< 15 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }

  func testSharedInstance() {
    let cache1 = PIImageCache.shared
    let cache2 = PIImageCache.shared
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 10 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 10 {
      (image, result) = cache1.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache2.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }
  
  func testCacheMaxCount() {
    let config = PIImageCache.Config()
    config.maxMemorySum = 5
    config.limitByteSize = 3 * 1024 * 1024
    let cache = PIImageCache(config: config)
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 10 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 5 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 5 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 5 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }

  func testCacheMaxSize() {
    let config = PIImageCache.Config()
    config.maxMemorySum = 10
    config.limitByteSize = 100
    let cache = PIImageCache(config: config)
    let url = NSURL(string: "http://place-hold.it/200x200")!
    var image: UIImage?, result: PIImageCache.Result
    (image, result) = cache.perform(url)
    XCTAssert(result != .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    (image, result) = cache.perform(url)
    XCTAssert(result == .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
  }
  
  func testSyncGet() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    let image = cache.get(url)!
    XCTAssert(image.size.width == 200 && image.size.height == 200 , "Pass")
  }
  
  func testAsyncGet() {<commit_msg>testcaseの修正<commit_after>
// https://github.com/pixel-ink/PIImageCache

import UIKit
import XCTest

class PIImageMemoryCacheTests: XCTestCase {
  
  func testDownload() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    let (image,dataSize) = cache.download(url)!
    XCTAssert(dataSize == 926 , "Pass")
    XCTAssert(image.size.width == 200 && image.size.height == 200 , "Pass")
  }
  
  func testPerform() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    var image: UIImage?, result: PIImageCache.Result
    (image, result) = cache.perform(url)
    XCTAssert(result != .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    (image, result) = cache.perform(url)
    XCTAssert(result == .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
  }
  
  func testCacheLimit() {
    let cache = PIImageCache()
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 15 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 10 ..< 15 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 10 ..< 15 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }

  func testSharedInstance() {
    let cache1 = PIImageCache.shared
    let cache2 = PIImageCache.shared
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 10 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 10 {
      (image, result) = cache1.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 10 {
      (image, result) = cache2.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }
  
  func testCacheMaxCount() {
    let config = PIImageCache.Config()
    config.maxMemorySum = 5
    config.limitByteSize = 3 * 1024 * 1024
    let cache = PIImageCache(config: config)
    var image: UIImage?, result: PIImageCache.Result
    var urls :[NSURL] = []
    for i in 0 ..< 10 {
      urls.append(NSURL(string: "http://place-hold.it/200x200/2ff&text=No.\(i)")!)
    }
    for i in 0 ..< 5 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 0 ..< 5 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result == .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
    for i in 5 ..< 10 {
      (image, result) = cache.perform(urls[i])
      XCTAssert(result != .MemoryHit, "Pass")
      XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    }
  }

  func testCacheMaxSize() {
    let config = PIImageCache.Config()
    config.usingDiskCache = false
    config.maxMemorySum = 10
    config.limitByteSize = 100
    let cache = PIImageCache(config: config)
    let url = NSURL(string: "http://place-hold.it/200x200")!
    var image: UIImage?, result: PIImageCache.Result
    (image, result) = cache.perform(url)
    XCTAssert(result != .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
    (image, result) = cache.perform(url)
    XCTAssert(result != .MemoryHit, "Pass")
    XCTAssert(image!.size.width == 200 && image!.size.height == 200 , "Pass")
  }
  
  func testSyncGet() {
    let cache = PIImageCache()
    let url = NSURL(string: "http://place-hold.it/200x200")!
    let image = cache.get(url)!
    XCTAssert(image.size.width == 200 && image.size.height == 200 , "Pass")
  }
  
  func testAsyncGet() {
{'fraction_non_alphanumeric': 0.17416516696660667, 'fraction_numerical': 0.042191561687662464, 'mean_word_length': 2.8019764348156593, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105501', 'n_tokens_mistral': 3894, 'n_tokens_neox': 3470, 'n_words': 756}