aboutsummaryrefslogtreecommitdiff
path: root/binary_search_tool/test/common.py
blob: 6632a4c7c9160cdc14779362835694b0ecec6d47 (plain)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Common utility functions."""

DEFAULT_OBJECT_NUMBER = 1238
DEFAULT_BAD_OBJECT_NUMBER = 23
OBJECTS_FILE = "objects.txt"
WORKING_SET_FILE = "working_set.txt"


def ReadWorkingSet():
    working_set = []
    with open(WORKING_SET_FILE, "r", encoding="utf-8") as f:
        for l in f:
            working_set.append(int(l))
    return working_set


def WriteWorkingSet(working_set):
    with open(WORKING_SET_FILE, "w", encoding="utf-8") as f:
        for o in working_set:
            f.write("{0}\n".format(o))


def ReadObjectsFile():
    objects_file = []
    with open(OBJECTS_FILE, "r", encoding="utf-8") as f:
        for l in f:
            objects_file.append(int(l))
    return objects_file


def ReadObjectIndex(filename):
    object_index = []
    with open(filename, "r", encoding="utf-8") as f:
        for o in f:
            object_index.append(int(o))
    return object_index