Skip to content

Instantly share code, notes, and snippets.

@rbrovko
Created August 9, 2019 06:02
Show Gist options
  • Save rbrovko/66aa9527164f7a07b9573b0756caedc8 to your computer and use it in GitHub Desktop.
Save rbrovko/66aa9527164f7a07b9573b0756caedc8 to your computer and use it in GitHub Desktop.
testNote_whenMutableNote_rateConditions
import XCTest
@testable import Notes
class NoteTests: XCTestCase {
private let uid = "123"
private let title = "title"
private let content = "text"
private let importance = Note.Importance.normal
private var sut: Note!
override func setUp() {
super.setUp()
sut = Note(title: title, content: content, importance: importance)
}
override func tearDown() {
sut = nil
super.tearDown()
}
func testNote_whenMutableNote_rateConditions() {
let group = DispatchGroup()
var obj: Note! = sut
for i in 0..<1000 {
group.enter()
DispatchQueue.global().async {
let sleepVal = arc4random() % 1000
usleep(sleepVal)
obj.title = "Text #\(i)"
obj.content = "#\(i)"
let r = CGFloat(arc4random() % 256) / 255
let g = CGFloat(arc4random() % 256) / 255
let b = CGFloat(arc4random() % 256) / 255
let color = UIColor(red: r, green: g, blue: b, alpha: 1)
obj.color = color
let isEqualTitle = obj.title == "Text #\(i)"
print("=> \(i) \(obj.color == color) isEqualTitle: \(isEqualTitle) '\(obj.title)' '\(obj.content)'")
}
}
let result = group.wait(timeout: DispatchTime.now() + 5)
XCTAssert(result == .success)
}
}
=> 2 true isEqualTitle: true 'Text #2' '#2'
=> 0 false isEqualTitle: true 'Text #2' '#2'
=> 4 true isEqualTitle: true 'Text #2' '#2'
=> 3 false isEqualTitle: false 'Text #2' '#2'
=> 8 true isEqualTitle: true 'Text #8' '#8'
=> 13 true isEqualTitle: true 'Text #13' '#13'
=> 26 true isEqualTitle: true 'Text #26' '#26'
=> 5 true isEqualTitle: false 'Text #19' '#19'
=> 22 true isEqualTitle: false 'Text #19' '#19'
=> 19 true isEqualTitle: true 'Text #19' '#19'
=> 21 true isEqualTitle: true 'Text #1' '#1'
=> 1 true isEqualTitle: true 'Text #1' '#1'
=> 33 true isEqualTitle: true 'Text #33' '#33'
=> 11 true isEqualTitle: true 'Text #11' '#11'
=> 40 true isEqualTitle: true 'Text #40' '#40'
=> 25 true isEqualTitle: true 'Text #25' '#25'
=> 41 true isEqualTitle: true 'Text #41' '#41'
=> 18 true isEqualTitle: true 'Text #18' '#18'
=> 31 true isEqualTitle: true 'Text #31' '#31'
=> 9 false isEqualTitle: false 'Text #31' '#31'
=> 14 false isEqualTitle: false 'Text #31' '#31'
=> 6 true isEqualTitle: true 'Text #6' '#6'
=> 20 true isEqualTitle: false 'Text #6' '#6'
=> 53 true isEqualTitle: false 'Text #43' '#43'
=> 43 true isEqualTitle: true 'Text #43' '#43'
=> 23 true isEqualTitle: true 'Text #68' '#68'
=> 44 true isEqualTitle: true 'Text #44' '#44'
=> 57 true isEqualTitle: true 'Text #57' '#57'
=> 35 true isEqualTitle: true 'Text #35' '#35'
=> 15 true isEqualTitle: false 'Text #38' '#38'
=> 38 true isEqualTitle: true 'Text #38' '#38'
=> 47 false isEqualTitle: true 'Text #47' '#47'
=> 7 true isEqualTitle: false 'Text #47' '#47'
=> 27 true isEqualTitle: true 'Text #27' '#27'
=> 51 true isEqualTitle: false 'Text #27' '#27'
=> 12 true isEqualTitle: false 'Text #34' '#34'
=> 37 true isEqualTitle: false 'Text #77' '#77'
=> 45 true isEqualTitle: false 'Text #39' '#39'
=> 56 true isEqualTitle: false 'Text #32' '#32'
=> 39 true isEqualTitle: true 'Text #39' '#39'
=> 69 true isEqualTitle: true 'Text #69' '#69'
=> 28 true isEqualTitle: true 'Text #28' '#28'
=> 92 true isEqualTitle: false 'Text #75' '#75'
=> 81 true isEqualTitle: false 'Text #87' '#87'
=> 68 true isEqualTitle: true 'Text #68' '#68'
=> 97 true isEqualTitle: true 'Text #97' '#97'
=> 86 true isEqualTitle: true 'Text #86' '#86'
=> 10 true isEqualTitle: true 'Text #46' '#46'
=> 46 true isEqualTitle: true 'Text #46' '#46'
=> 74 true isEqualTitle: false 'Text #78' '#78'
=> 55 true isEqualTitle: false 'Text #37' '#37'
=> 77 true isEqualTitle: true 'Text #77' '#77'
=> 17 false isEqualTitle: false 'Text #77' '#77'
=> 34 true isEqualTitle: true 'Text #34' '#34'
=> 93 true isEqualTitle: false 'Text #80' '#80'
=> 104 true isEqualTitle: false 'Text #80' '#80'
=> 65 false isEqualTitle: false 'Text #32' '#32'
=> 76 true isEqualTitle: false 'Text #32' '#32'
=> 29 true isEqualTitle: true 'Text #29' '#29'
=> 48 false isEqualTitle: false 'Text #69' '#69'
=> 30 true isEqualTitle: true 'Text #30' '#30'
=> 59 false isEqualTitle: true 'Text #59' '#59'
=> 60 true isEqualTitle: false 'Text #59' '#59'
=> 75 true isEqualTitle: true 'Text #81' '#61'
=> 49 true isEqualTitle: false 'Text #44' '#44'
=> 61 false isEqualTitle: false 'Text #87' '#87'
=> 87 true isEqualTitle: true 'Text #87' '#87'
=> 16 false isEqualTitle: false 'Text #68' '#68'
=> 95 true isEqualTitle: true 'Text #95' '#95'
=> 85 false isEqualTitle: true 'Text #85' '#85'
=> 90 true isEqualTitle: false 'Text #85' '#85'
=> 70 true isEqualTitle: true 'Text #70' '#42'
=> 83 false isEqualTitle: true 'Text #83' '#54'
=> 42 true isEqualTitle: false 'Text #54' '#54'
=> 54 true isEqualTitle: true 'Text #54' '#54'
=> 66 true isEqualTitle: true 'Text #66' '#66'
=> 63 true isEqualTitle: false 'Text #67' '#67'
=> 67 true isEqualTitle: true 'Text #67' '#67'
=> 58 true isEqualTitle: true 'Text #58' '#58'
=> 71 true isEqualTitle: true 'Text #71' '#71'
=> 73 true isEqualTitle: true 'Text #73' '#73'
=> 82 true isEqualTitle: true 'Text #82' '#82'
=> 88 true isEqualTitle: false 'Text #84' '#84'
=> 94 true isEqualTitle: false 'Text #84' '#84'
=> 84 true isEqualTitle: true 'Text #84' '#84'
=> 62 true isEqualTitle: false 'Text #89' '#89'
=> 89 true isEqualTitle: true 'Text #89' '#89'
=> 133 true isEqualTitle: false 'Text #134' '#134'
=> 52 true isEqualTitle: false 'Text #89' '#89'
=> 72 true isEqualTitle: true 'Text #72' '#72'
=> 64 true isEqualTitle: true 'Text #64' '#57'
=> 147 true isEqualTitle: true 'Text #147' '#147'
=> 79 true isEqualTitle: false 'Text #78' '#78'
=> 50 true isEqualTitle: true 'Text #50' '#50'
=> 78 true isEqualTitle: true 'Text #78' '#78'
=> 36 true isEqualTitle: false 'Text #32' '#32'
=> 80 true isEqualTitle: true 'Text #80' '#80'
=> 32 true isEqualTitle: true 'Text #32' '#32'
=> 114 true isEqualTitle: true 'Text #114' '#114'
=> 103 true isEqualTitle: true 'Text #103' '#103'
=> 115 true isEqualTitle: true 'Text #115' '#115'
=> 98 true isEqualTitle: true 'Text #98' '#98'
=> 91 true isEqualTitle: true 'Text #91' '#91'
=> 145 true isEqualTitle: true 'Text #145' '#145'
=> 116 true isEqualTitle: true 'Text #116' '#116'
=> 101 true isEqualTitle: true 'Text #101' '#101'
=> 118 true isEqualTitle: true 'Text #118' '#118'
=> 113 true isEqualTitle: true 'Text #113' '#111'
=> 111 true isEqualTitle: true 'Text #111' '#111'
=> 102 true isEqualTitle: true 'Text #102' '#106'
=> 163 true isEqualTitle: true 'Text #163' '#163'
=> 135 false isEqualTitle: false 'Text #144' '#149'
=> 152 false isEqualTitle: true 'Text #152' '#152'
=> 144 false isEqualTitle: false 'Text #168' '#169'
=> 99 true isEqualTitle: true 'Text #99' '#99'
=> 127 true isEqualTitle: true 'Text #127' '#127'
=> 158 true isEqualTitle: true 'Text #158' '#158'
=> 123 true isEqualTitle: true 'Text #123' '#123'
=> 119 true isEqualTitle: false 'Text #107' '#107'
=> 175 true isEqualTitle: true 'Text #175' '#175'
=> 109 true isEqualTitle: false 'Text #107' '#107'
=> 126 true isEqualTitle: true 'Text #126' '#126'
=> 112 true isEqualTitle: false 'Text #128' '#128'
=> 128 true isEqualTitle: true 'Text #128' '#128'
=> 124 true isEqualTitle: true 'Text #124' '#124'
=> 120 false isEqualTitle: false 'Text #121' '#121'
=> 125 true isEqualTitle: true 'Text #121' '#121'
=> 121 true isEqualTitle: false 'Text #122' '#122'
=> 122 true isEqualTitle: true 'Text #122' '#122'
=> 146 true isEqualTitle: true 'Text #146' '#146'
=> 176 true isEqualTitle: true 'Text #176' '#176'
=> 148 true isEqualTitle: true 'Text #148' '#148'
=> 141 true isEqualTitle: false 'Text #139' '#130'
=> 170 true isEqualTitle: false 'Text #160' '#160'
=> 137 false isEqualTitle: false 'Text #139' '#130'
=> 130 false isEqualTitle: false 'Text #139' '#130'
=> 153 true isEqualTitle: false 'Text #188' '#188'
=> 188 true isEqualTitle: true 'Text #188' '#188'
=> 96 false isEqualTitle: false 'Text #89' '#89'
=> 24 true isEqualTitle: true 'Text #10' '#10'
=> 162 true isEqualTitle: true 'Text #145' '#145'
=> 100 true isEqualTitle: true 'Text #116' '#116'
=> 132 true isEqualTitle: false 'Text #136' '#136'
=> 136 true isEqualTitle: true 'Text #157' '#157'
=> 204 true isEqualTitle: true 'Text #204' '#204'
=> 157 true isEqualTitle: true 'Text #157' '#157'
=> 183 true isEqualTitle: false 'Text #180' '#180'
=> 151 true isEqualTitle: true 'Text #151' '#151'
=> 140 true isEqualTitle: true 'Text #140' '#140'
=> 106 true isEqualTitle: false 'Text #110' '#110'
=> 110 true isEqualTitle: true 'Text #110' '#110'
=> 161 false isEqualTitle: false 'Text #171' '#171'
=> 131 false isEqualTitle: false 'Text #171' '#171'
=> 174 true isEqualTitle: true 'Text #174' '#174'
=> 149 true isEqualTitle: false 'Text #171' '#171'
=> 212 true isEqualTitle: false 'Text #202' '#202'
=> 171 true isEqualTitle: true 'Text #169' '#169'
=> 196 true isEqualTitle: false 'Text #206' '#206'
=> 169 false isEqualTitle: true 'Text #169' '#169'
=> 108 true isEqualTitle: false 'Text #123' '#123'
=> 117 false isEqualTitle: false 'Text #123' '#123'
=> 107 true isEqualTitle: true 'Text #107' '#107'
=> 172 true isEqualTitle: true 'Text #172' '#150'
=> 150 true isEqualTitle: true 'Text #150' '#150'
=> 165 true isEqualTitle: true 'Text #165' '#165'
=> 178 true isEqualTitle: false 'Text #159' '#159'
=> 159 true isEqualTitle: true 'Text #159' '#159'
=> 219 true isEqualTitle: true 'Text #219' '#219'
=> 187 true isEqualTitle: false 'Text #155' '#155'
=> 142 false isEqualTitle: false 'Text #146' '#146'
=> 139 false isEqualTitle: true 'Text #139' '#130'
=> 160 true isEqualTitle: true 'Text #160' '#160'
=> 173 true isEqualTitle: false 'Text #188' '#188'
=> 143 true isEqualTitle: true 'Text #143' '#143'
=> 134 true isEqualTitle: true 'Text #134' '#134'
=> 129 true isEqualTitle: false 'Text #151' '#151'
=> 180 true isEqualTitle: true 'Text #180' '#180'
=> 200 true isEqualTitle: true 'Text #200' '#231'
=> 192 true isEqualTitle: true 'Text #192' '#192'
=> 154 false isEqualTitle: false 'Text #164' '#164'
=> 185 true isEqualTitle: false 'Text #164' '#164'
=> 182 true isEqualTitle: false 'Text #164' '#164'
=> 156 false isEqualTitle: false 'Text #164' '#164'
=> 179 true isEqualTitle: false 'Text #164' '#164'
=> 164 true isEqualTitle: true 'Text #164' '#164'
=> 238 true isEqualTitle: true 'Text #238' '#238'
=> 205 true isEqualTitle: false 'Text #181' '#181'
=> 181 true isEqualTitle: true 'Text #181' '#181'
=> 166 true isEqualTitle: false 'Text #211' '#211'
=> 211 true isEqualTitle: true 'Text #211' '#211'
=> 177 true isEqualTitle: true 'Text #177' '#177'
=> 201 true isEqualTitle: false 'Text #174' '#174'
=> 138 false isEqualTitle: false 'Text #171' '#171'
=> 202 true isEqualTitle: true 'Text #202' '#202'
=> 105 true isEqualTitle: true 'Text #105' '#105'
=> 168 true isEqualTitle: false 'Text #169' '#169'
=> 249 true isEqualTitle: false 'Text #215' '#215'
=> 215 true isEqualTitle: true 'Text #215' '#215'
=> 186 true isEqualTitle: true 'Text #186' '#186'
=> 155 true isEqualTitle: true 'Text #155' '#155'
=> 220 true isEqualTitle: true 'Text #218' '#218'
=> 218 true isEqualTitle: false 'Text #184' '#184'
=> 228 false isEqualTitle: false 'Text #184' '#184'
=> 191 true isEqualTitle: false 'Text #184' '#184'
=> 221 false isEqualTitle: false 'Text #184' '#184'
=> 184 true isEqualTitle: true 'Text #193' '#216'
=> 193 true isEqualTitle: false 'Text #216' '#216'
=> 216 true isEqualTitle: true 'Text #216' '#216'
=> 195 true isEqualTitle: true 'Text #195' '#195'
=> 214 true isEqualTitle: false 'Text #190' '#190'
=> 224 true isEqualTitle: false 'Text #190' '#190'
=> 190 true isEqualTitle: true 'Text #190' '#190'
=> 227 true isEqualTitle: false 'Text #254' '#254'
=> 207 true isEqualTitle: true 'Text #207' '#207'
=> 198 true isEqualTitle: true 'Text #198' '#198'
=> 226 true isEqualTitle: false 'Text #200' '#200'
=> 167 true isEqualTitle: false 'Text #140' '#140'
=> 199 true isEqualTitle: true 'Text #182' '#182'
=> 231 false isEqualTitle: false 'Text #192' '#192'
=> 262 true isEqualTitle: true 'Text #262' '#262'
=> 240 true isEqualTitle: true 'Text #240' '#240'
=> 217 true isEqualTitle: true 'Text #217' '#217'
=> 232 true isEqualTitle: false 'Text #238' '#238'
=> 189 false isEqualTitle: false 'Text #211' '#211'
=> 197 true isEqualTitle: false 'Text #237' '#229'
=> 229 true isEqualTitle: false 'Text #237' '#229'
=> 237 true isEqualTitle: true 'Text #237' '#229'
=> 233 true isEqualTitle: true 'Text #233' '#233'
=> 251 true isEqualTitle: false 'Text #209' '#209'
=> 246 true isEqualTitle: false 'Text #209' '#209'
=> 258 true isEqualTitle: true 'Text #258' '#258'
=> 203 true isEqualTitle: false 'Text #209' '#209'
=> 225 true isEqualTitle: true 'Text #225' '#225'
=> 257 true isEqualTitle: true 'Text #257' '#257'
=> 250 false isEqualTitle: false 'Text #213' '#213'
=> 243 true isEqualTitle: true 'Text #243' '#243'
=> 206 true isEqualTitle: true 'Text #206' '#206'
=> 208 true isEqualTitle: false 'Text #186' '#186'
=> 261 true isEqualTitle: false 'Text #260' '#260'
=> 260 true isEqualTitle: true 'Text #260' '#260'
=> 223 true isEqualTitle: true 'Text #223' '#223'
=> 236 true isEqualTitle: true 'Text #236' '#236'
=> 289 true isEqualTitle: false 'Text #280' '#280'
=> 280 true isEqualTitle: true 'Text #280' '#280'
=> 230 true isEqualTitle: true 'Text #230' '#230'
=> 248 true isEqualTitle: false 'Text #230' '#230'
=> 222 true isEqualTitle: true 'Text #222' '#222'
=> 256 false isEqualTitle: false 'Text #222' '#222'
=> 242 true isEqualTitle: true 'Text #242' '#242'
=> 241 true isEqualTitle: true 'Text #241' '#241'
=> 194 true isEqualTitle: true 'Text #194' '#194'
=> 312 true isEqualTitle: true 'Text #312' '#312'
=> 210 true isEqualTitle: true 'Text #210' '#210'
=> 264 true isEqualTitle: false 'Text #255' '#255'
=> 255 true isEqualTitle: true 'Text #255' '#255'
=> 235 true isEqualTitle: false 'Text #277' '#277'
=> 273 false isEqualTitle: false 'Text #277' '#277'
=> 239 true isEqualTitle: false 'Text #277' '#277'
=> 277 false isEqualTitle: true 'Text #277' '#277'
=> 245 true isEqualTitle: true 'Text #245' '#245'
=> 234 true isEqualTitle: true 'Text #234' '#234'
=> 297 false isEqualTitle: false 'Text #316' '#316'
=> 244 true isEqualTitle: true 'Text #244' '#244'
=> 278 true isEqualTitle: true 'Text #278' '#278'
=> 268 true isEqualTitle: true 'Text #268' '#268'
=> 282 true isEqualTitle: false 'Text #258' '#258'
=> 265 false isEqualTitle: false 'Text #258' '#258'
=> 313 false isEqualTitle: false 'Text #288' '#288'
=> 302 true isEqualTitle: true 'Text #302' '#302'
=> 299 true isEqualTitle: false 'Text #253' '#253'
=> 303 true isEqualTitle: true 'Text #303' '#303'
=> 247 true isEqualTitle: true 'Text #247' '#247'
=> 259 true isEqualTitle: true 'Text #259' '#259'
=> 311 true isEqualTitle: true 'Text #311' '#311'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment