<commit_before>//
//  TestRenderData.swift
//  AsyncImageView
//
//  Created by <NAME> on 11/22/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import ReactiveCocoa

import Quick
import Nimble

@testable import AsyncImageView

internal enum TestData: CGFloat, Hashable {
	case A = 1.0
	case B = 2.0
	case C = 3.0
}

extension TestData: ImageViewDataType {
	var data: TestData {
		return self
	}

	func renderDataWithSize(size: CGSize) -> TestRenderData {
		return RenderData(data: self.data, size: size)
	}
}

internal struct TestRenderData: RenderDataType {
	let data: TestData
	let size: CGSize

	var hashValue: Int {
		return data ^^^ size.width ^^^ size.height
	}
}

internal func ==(lhs: TestRenderData, rhs: TestRenderData) -> Bool {
	return (lhs.data == rhs.data &&
			lhs.size == rhs.size)
}

internal final class TestRenderer: RendererType {
	var renderedImages: Atomic<[TestRenderData]> = Atomic([])

	func renderImageWithData(data: TestRenderData) ->  SignalProducer<UIImage, NoError> {
		let size = data.size
		assert(size.width > 0 && size.height > 0, "Should not attempt to render with invalid size: \(size)")

		let renderer = ContextRenderer<TestRenderData>(scale: data.data.rawValue, opaque: true) { _ in
			// nothing to render
		}

		return renderer
			.asyncRenderer(ImmediateScheduler())
			.renderImageWithData(data)
			.on(started: {
				self.renderedImages.modify { $0 + [data] }
			})<commit_msg>TestRenderData: exposed ContextRenderer for TestRenderData<commit_after>//
//  TestRenderData.swift
//  AsyncImageView
//
//  Created by <NAME> on 11/22/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit
import ReactiveCocoa

import Quick
import Nimble

@testable import AsyncImageView

internal enum TestData: CGFloat, Hashable {
	case A = 1.0
	case B = 2.0
	case C = 3.0
}

extension TestData: ImageViewDataType {
	var data: TestData {
		return self
	}

	func renderDataWithSize(size: CGSize) -> TestRenderData {
		return RenderData(data: self.data, size: size)
	}
}

internal struct TestRenderData: RenderDataType {
	let data: TestData
	let size: CGSize

	var hashValue: Int {
		return data ^^^ size.width ^^^ size.height
	}
}

internal func ==(lhs: TestRenderData, rhs: TestRenderData) -> Bool {
	return (lhs.data == rhs.data &&
			lhs.size == rhs.size)
}

internal final class TestRenderer: RendererType {
	var renderedImages: Atomic<[TestRenderData]> = Atomic([])

	func renderImageWithData(data: TestRenderData) -> SignalProducer<UIImage, NoError> {
		return TestRenderer
			.rendererForData(data)
			.asyncRenderer(ImmediateScheduler())
			.renderImageWithData(data)
			.on(started: {
				self.renderedImages.modify { $0 + [data] }
			})
	}

	static func rendererForData(data: TestRenderData) -> ContextRenderer<TestRenderData> {
		let size = data.size
		assert(size.width > 0 && size.height > 0, "Should not attempt to render with invalid size: \(size)")

		return ContextRenderer<TestRenderData>(scale: data.data.rawValue, opaque: true) { _ in
			// nothing to render
		}
{'fraction_non_alphanumeric': 0.11625615763546798, 'fraction_numerical': 0.012479474548440065, 'mean_word_length': 3.977124183006536, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1069616', 'n_tokens_mistral': 1099, 'n_tokens_neox': 995, 'n_words': 277}