feat: implement testing functions for Contact, Person, Student, and StudentShort classes; add sample student data

lab2
Artem-Darius Weber 4 weeks ago
parent 80e86e0f99
commit be544ae87d

@ -1,59 +1,61 @@
require_relative 'contact'
require_relative 'person'
require_relative 'student' require_relative 'student'
require_relative 'student_short' require_relative 'student_short'
require_relative 'student_repository'
begin def test_classes
student_string = "Норакет Норакет Норакет | ID: 2 | Phone: +1234567890 | Telegram: @noracat | Email: nora@example.com | Git: https://github.com/nora" contact = Contact.new(phone: '+798912465', telegram: '@example_user', email: 'test@example.com')
student_from_string = Student.from_string(student_string) puts "Contact Info: #{contact.info}"
puts "Создан объект из строки:\n#{student_from_string}"
person = Person.new(id: '1', git: 'https://github.com/example', contact: contact)
puts "Person Contact Info: #{person.contact_info}"
student1 = Student.new(
surname: 'Алексеевич',
name: 'Артем-Дариус',
patronymic: 'Вебер',
id: 1,
git: 'https://github.com/space-creator'
)
student1.set_contacts( student = Student.new(
phone: '+79891242223', id: '2',
telegram: '@alstroemeria22', git: 'https://github.com/student_example',
email: 'no-replay@djft.ru' contact: contact,
surname: 'Иванов',
name: 'Иван',
patronymic: 'Иванович'
) )
puts "Student Full Info: #{student.to_s}"
puts "Student Initials: #{student.surname_and_initials}"
puts "Student Contact Info: #{student.contact_info}"
puts student1.get_info
puts "Surname and Initials: #{student1.surname_and_initials}"
puts "Git Info: #{student1.git_info}"
puts "Contact Info: #{student1.contact_info}"
student2 = Student.new( student_short = StudentShort.from_student(student)
surname: 'Норакет', puts "Student Short Info: #{student_short.to_s}"
name: 'Норакет',
patronymic: 'Фамилия'
)
student2.set_contacts(
phone: '+70000000000'
)
puts student1 file_path = 'students.txt'
puts '-' * 40 students = StudentRepository.read_from_txt(file_path)
puts student2 puts "Read Students from File:"
students.each { |s| puts s.to_s }
student_short_from_student = StudentShort.new(student1)
puts "StudentShort from Student object:" output_path = 'output_students.txt'
puts "ID: #{student_short_from_student.id}" StudentRepository.write_to_txt(output_path, students)
puts "Surname and Initials: #{student_short_from_student.surname_initials}" puts "Students written to file: #{output_path}"
puts "Git: #{student_short_from_student.git}" end
puts "Contact: #{student_short_from_student.contact}"
student_short_from_string = StudentShort.from_string(5, 'Skye A.A., Git: https://github.com/skye, Contact: Phone: +4923467890') def test_parsing
puts "StudentShort from string:" student_string = 'Иванов Иван Иванович | ID: 3 | Phone: +79876543210 | Telegram: @ivan_user | Email: ivan@example.com | Git: https://github.com/ivanov'
puts "ID: #{student_short_from_string.id}" student = Student.from_string(student_string)
puts "Surname and Initials: #{student_short_from_string.surname_initials}" puts "Parsed Student: #{student.to_s}"
puts "Git: #{student_short_from_string.git}"
puts "Contact: #{student_short_from_string.contact}" short_string = 'Иванов И.И., Git: https://github.com/ivanov, Contact: Phone: +79876543210'
rescue ArgumentError => e student_short = StudentShort.from_string('4', short_string)
puts "Ошибка: #{e.message}" puts "Parsed StudentShort: #{student_short.to_s}"
end
if __FILE__ == $0
puts "=== Testing Classes ==="
test_classes
puts "\n=== Testing Parsing ==="
test_parsing
end end

@ -0,0 +1,3 @@
Иванов Иван Иванович | ID: 1 | Phone: +12345678901 | Telegram: @ivanov_user | Email: ivanov@example.com | Git: https://github.com/ivanov
Петров Петр Петрович | ID: 2 | Phone: +98765432101 | Telegram: @petrov_user | Email: petrov@example.com | Git: https://github.com/petrov
Сидоров Сидор Сидорович | ID: 3 | Phone: +56789012345 | Telegram: @sidorov_user | Email: sidorov@example.com | Git: https://github.com/sidorov
Loading…
Cancel
Save