Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.swift
- // BTreeTestsGenerator
- //
- // Created by Oleg Koptev on 25.11.2020.
- //
- import Foundation
- let commands = ["insert", "find"]
- for i in 1...5 {
- var output = ""
- let linesAmount = Int.random(in: 1..<100)
- var keys: [Int] = []
- for _ in 0..<linesAmount {
- let commandNumber = Int.random(in: 0..<commands.count)
- switch commandNumber {
- case 0:
- var n1: Int, n2: Int;
- if (Bool.random()) {
- n1 = Int.random(in: -100_000_000..<100_000_000)
- } else {
- n1 = Int.random(in: -100..<100)
- }
- if (Bool.random()) {
- n2 = Int.random(in: -100_000_000..<100_000_000)
- } else {
- n2 = Int.random(in: -100..<100)
- }
- keys.append(n1)
- output += "\(commands[0]) \(n1) \(n2)\n"
- case 1:
- var n1: Int
- if (Bool.random()) {
- n1 = Int.random(in: -100_000_000..<100_000_000)
- } else {
- n1 = keys.randomElement() ?? 0
- }
- output += "\(commands[1]) \(n1)\n"
- default:
- continue
- }
- }
- try output.write(toFile: "test\(i).txt", atomically: true, encoding: .utf8)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement