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