コード例 #1
0
ファイル: console.py プロジェクト: TamasFlorin/UBB
def ui_add_student(students):
    code = input("code:")
    
    if not ui_is_valid_code(code):
        raise ValueError("Invalid student code provided.")
    
    if len(get_students_by_code(students,code))>0:
        raise ValueError("Duplicate student code.")
    
    name = input("name:")
    
    if len(name)<3:
        raise ValueError("Student name must be of length greater or equal to 3.")
    
    hometown = input("hometown:")
    
    if len(hometown)<3:
        raise ValueError("Student hometown must be of length greater or equal to 3.")
    
    grade = input("grade:")
    
    if get_type(grade) is not int:
        raise ValueError("The student grade must be an integer.")
    
    grade = int(grade)
    
    if grade < 1 or grade > 10:
        raise ValueError("Invalid grade value provided.")
    
    add_student(students,code,name,hometown,grade)
コード例 #2
0
ファイル: UI.py プロジェクト: AndreiMsc/Students-Informations
def UI_add(std_list, args):
    if len(args) != 4:
        raise ValueError("Incorrect number of arguments!")
    code = args[0]
    name = args[1]
    hometown = args[2]
    grade = args[3]
    codes = UI_get_codes(std_list)
    if not name.isalpha() or len(name) < 3:
        raise ValueError("Invalid name!")
    if not hometown.isalpha() or len(hometown) < 3:
        raise ValueError("Invalid hometown!")
    try:
        float(grade)
    except ValueError:
        raise ValueError("Invalid grade!")
    if float(grade) < 0 or float(grade) > 10:
        raise ValueError("Invalid grade!")
    if len(code) != 8:
        raise ValueError("Invalid code!")
    elif not code[:4].isalpha():
        raise ValueError("Invalid code!")
    elif not code[4:].isdigit():
        raise ValueError("Invalid code!")
    elif code in codes:
        raise ValueError("Already a student with that code!")
    add_student(std_list, code, name, hometown, grade)
コード例 #3
0
def test_modify_student_grade():
    students = []

    add_student(students, "miie1234", "John", "Alba Iulia", 10)

    modify_student_grade(students, "miie1234", 9)

    assert students[0]["grade"] == 9
コード例 #4
0
def test_add():
    std_list = []
    add_student(std_list, "abcd1234", "test", "home", "5")
    assert (std_list == [{
        "code": "abcd1234",
        "name": "test",
        "hometown": "home",
        "grade": "5"
    }])
コード例 #5
0
def test_add_student():
    students = []
    add_student(students, "miie1234", "John", "Alba Iulia", 10)

    assert len(students) == 1

    add_student(students, "miie1246", "Ion", "Cluj", 9)

    assert len(students) == 2
コード例 #6
0
def test_penalize_students_group():
    students = []

    add_student(students, "miie1234", "John", "Alba Iulia", 10)
    add_student(students, "miie1246", "Ion", "Cluj", 9)

    reduce_grades_group(students, "12", 10)

    assert students[0]["grade"] == 9 and students[1]["grade"] == 8
コード例 #7
0
def test_get_students_by_hometown():
    students = []
    add_student(students, "miie1234", "John", "Alba Iulia", 10)
    add_student(students, "miie1246", "Ion", "Cluj", 9)
    add_student(students, "miie1230", "Razvan", "Cluj", 10)
    add_student(students, "miie1241", "Vlad", "Cluj", 9)

    res = get_students_by_hometown(students, "Cluj")

    assert len(res) == 3
コード例 #8
0
def test_get_from_hometown():
    std_list = []
    add_student(std_list, "abcd1231", "test", "home", "6")
    add_student(std_list, "abcd1232", "test", "house", "9")
    add_student(std_list, "abcd1233", "test", "home", "5")
    ht_std = get_students_from_hometown(std_list, "home")
    assert (ht_std == [{
        "code": "abcd1231",
        "name": "test",
        "hometown": "home",
        "grade": "9"
    }, {
        "code": "abcd1233",
        "name": "test",
        "hometown": "home",
        "grade": "5"
    }])
コード例 #9
0
def test_penalize():
    std_list = []
    add_student(std_list, "abca1234", "test", "home", "10")
    add_student(std_list, "abcb2134", "test", "home", "10")
    add_student(std_list, "abcd1234", "test", "home", "9")
    penalize_group(std_list, "12")
    assert (std_list == [{
        "code": "abca1234",
        "name": "test",
        "hometown": "home",
        "grade": "9.0"
    }, {
        "code": "abcb2134",
        "name": "test",
        "hometown": "home",
        "grade": "10"
    }, {
        "code": "abcd1234",
        "name": "test",
        "hometown": "home",
        "grade": "8.1"
    }])
コード例 #10
0
ファイル: console.py プロジェクト: TamasFlorin/UBB
def load_predefined_data(students):
    add_student(students, "miie1234", "Ion1", "Cluj", 9)
    add_student(students, "miie1235", "Ion2", "Satu Mare", 8)
    add_student(students, "miie1236", "Ion3", "Alba Iulia", 7)
    add_student(students, "miie1237", "Ion4", "Alba Iulia", 6)
    add_student(students, "miie1838", "Ion5", "Alba Iulia", 5)
    add_student(students, "miie1739", "Ion6", "Alba Iulia", 4)
    add_student(students, "miie1630", "Ion7", "Alba Iulia", 3)
    add_student(students, "miie1531", "Ion8", "Alba Iulia", 2)
    add_student(students, "miie1432", "Ion9", "Alba Iulia", 3)
    add_student(students, "miie1333", "Ion0", "Baia Mare", 10)