-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_test.py
More file actions
60 lines (50 loc) · 2.21 KB
/
Copy pathmake_test.py
File metadata and controls
60 lines (50 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import random
def generate_test(total_time, tasks):
"""
Gera os dados de teste conforme a descrição do problema.
Args:
total_time (int): Tempo total de simulação.
tasks (list): Lista de tuplas contendo o nome da tarefa, o período e o tempo de burst CPU.
Returns:
str: String formatada conforme o formato especificado no problema.
"""
test_data = f"{total_time}\n"
for task in tasks:
test_data += f"{task[0]} {task[1]} {task[2]}\n"
return test_data
def generate_random_test(num_tasks, total_time_range, period_range, cpu_burst_range):
"""
Gera dados de teste aleatórios.
Args:
num_tasks (int): Número de tarefas a serem geradas.
total_time_range (tuple): Faixa de valores para o tempo total de simulação (min, max).
period_range (tuple): Faixa de valores para o período das tarefas (min, max).
cpu_burst_range (tuple): Faixa de valores para o tempo de burst CPU das tarefas (min, max).
Returns:
tuple: Uma tupla contendo o tempo total de simulação e uma lista de tuplas com os dados das tarefas.
"""
total_time = random.randint(*total_time_range)
tasks = []
for _ in range(num_tasks):
task_name = f"T{_+1}"
period = random.randint(*period_range)
cpu_burst = random.randint(*cpu_burst_range)
tasks.append((task_name, period, cpu_burst))
return total_time, tasks
def write_to_file(file_name, data):
"""
Escreve os dados em um arquivo.
Args:
file_name (str): Nome do arquivo.
data (str): Dados a serem escritos no arquivo.
"""
with open(file_name, 'w') as file:
file.write(data.strip())
if __name__ == "__main__":
num_tasks = 100 # Número de tarefas
total_time_range = (100, 1000) # Faixa de valores para o tempo total de simulação
period_range = (10, 100) # Faixa de valores para o período das tarefas
cpu_burst_range = (1, 10) # Faixa de valores para o tempo de burst CPU das tarefas
total_time, tasks = generate_random_test(num_tasks, total_time_range, period_range, cpu_burst_range)
test_data = generate_test(total_time, tasks)
write_to_file("input.txt", test_data)