Advertisement
olegstankoptev

Untitled

Nov 25th, 2020 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.28 KB | None | 0 0
  1. //
  2. //  main.swift
  3. //  BTreeTestsGenerator
  4. //
  5. //  Created by Oleg Koptev on 25.11.2020.
  6. //
  7.  
  8. import Foundation
  9.  
  10. let commands = ["insert", "find"]
  11. for i in 1...5 {
  12.     var output = ""
  13.     let linesAmount = Int.random(in: 1..<100)
  14.     var keys: [Int] = []
  15.     for _ in 0..<linesAmount {
  16.         let commandNumber = Int.random(in: 0..<commands.count)
  17.         switch commandNumber {
  18.         case 0:
  19.             var n1: Int, n2: Int;
  20.             if (Bool.random()) {
  21.                 n1 = Int.random(in: -100_000_000..<100_000_000)
  22.             } else {
  23.                 n1 = Int.random(in: -100..<100)
  24.             }
  25.             if (Bool.random()) {
  26.                 n2 = Int.random(in: -100_000_000..<100_000_000)
  27.             } else {
  28.                 n2 = Int.random(in: -100..<100)
  29.             }
  30.             keys.append(n1)
  31.             output += "\(commands[0]) \(n1) \(n2)\n"
  32.         case 1:
  33.             var n1: Int
  34.             if (Bool.random()) {
  35.                 n1 = Int.random(in: -100_000_000..<100_000_000)
  36.             } else {
  37.                 n1 = keys.randomElement() ?? 0
  38.             }
  39.             output += "\(commands[1]) \(n1)\n"
  40.         default:
  41.             continue
  42.         }
  43.     }
  44.     try output.write(toFile: "test\(i).txt", atomically: true, encoding: .utf8)
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement