# Run from /backend with: python manage.py test matching
"""
Advanced real-world integration tests for the combined-text scoring algorithm.
"""
import unittest
[docs]
class Profile:
"""Profile object matching the current User schema."""
def __init__(
self,
hobbies="", goals="", clubs="",
major=None, minor=None, year="1",
international=False, commuter=False, firstgen=False,
outofstate=False, transfer=False,
):
self.hobbies = hobbies
self.goals = goals
self.clubs = clubs
self.major = major if major is not None else []
self.minor = minor if minor is not None else []
self.year = year
self.international = international
self.commuter = commuter
self.firstgen = firstgen
self.outofstate = outofstate
self.transfer = transfer
[docs]
class TestRealWorldScenarios(unittest.TestCase):
[docs]
def setUp(self):
from matching.scoring import calculate_match_score
self.calculate_match_score = calculate_match_score
[docs]
def test_cs_freshman_seeking_startup_mentor(self):
mentee = Profile(
hobbies="startups, entrepreneurship, coding, building products",
goals="I want to learn how to start a company and build products as a first year CS student.",
clubs="Entrepreneurship club, hackathons",
major=["Computer Science"], year="1",
)
mentor = Profile(
hobbies="entrepreneurship, software development, leadership",
goals="I founded a startup as a senior CS student and want to help others navigate that journey.",
clubs="Startup accelerator, CS mentorship",
major=["Computer Science"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] CS Startup Match: {score}")
self.assertGreaterEqual(score, 65.0)
[docs]
def test_pre_med_mentorship(self):
mentee = Profile(
hobbies="volunteering at clinics, biology research, patient care",
goals="I'm a biology pre-med student wanting to navigate the path to medical school.",
clubs="Pre-med society, research lab",
major=["Biology"], year="2",
)
mentor = Profile(
hobbies="medicine, healthcare, MCAT prep, research",
goals="I'm heading to medical school and want to help pre-meds navigate the journey.",
clubs="Pre-med mentorship, biology research",
major=["Biology"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] Pre-med Match: {score}")
self.assertGreaterEqual(score, 65.0)
[docs]
def test_engineering_to_consulting_mismatch(self):
mentee = Profile(
hobbies="consulting, case interviews, business strategy",
goals="I'm a mechanical engineering student who wants to break into management consulting.",
clubs="Consulting club, business society",
major=["Mechanical Engineering"], year="2",
)
mentor = Profile(
hobbies="robotics, CAD design, 3D printing, manufacturing",
goals="I want to work in robotics and mechanical design after graduation.",
clubs="Robotics club, engineering society",
major=["Mechanical Engineering"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] Engineering vs Consulting: {score}")
self.assertLessEqual(score, 60.0)
[docs]
def test_international_student_pairing(self):
mentee = Profile(
hobbies="coding, cultural exchange, international community events",
goals="As an international CS student, I want to navigate cultural adjustment and academic life.",
clubs="International student association, CS club",
major=["Computer Science"], year="1",
international=True, firstgen=True,
)
mentor = Profile(
hobbies="programming, international student support, mentorship",
goals="As an international CS student, I love helping other international students adjust.",
clubs="International mentorship program, CS club",
major=["Computer Science"], year="3",
international=True,
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] International Student Pairing: {score}")
self.assertGreaterEqual(score, 65.0)
[docs]
def test_women_in_stem_mentorship(self):
mentee = Profile(
hobbies="software engineering, networking, women in tech events",
goals="As a woman in CS, I want to find mentorship and build community in the tech industry.",
clubs="Women in CS, Society of Women Engineers",
major=["Computer Science"], year="1",
)
mentor = Profile(
hobbies="coding, mentorship, diversity in tech advocacy",
goals="As a female CS senior, I'm passionate about supporting women entering technology.",
clubs="Women in CS leadership, tech mentorship",
major=["Computer Science"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] Women in STEM Pairing: {score}")
self.assertGreaterEqual(score, 65.0)
[docs]
def test_career_switcher_scenario(self):
mentee = Profile(
hobbies="Python, statistics, data analysis",
goals="I started in biology but discovered a passion for data science. Learning programming.",
clubs="Data science club, Python users group",
major=["Biology"], year="2",
)
mentor = Profile(
hobbies="data science, machine learning, Python, teaching",
goals="As a statistics major in data science, I love helping people transition into the field.",
clubs="Data science mentorship, statistics club",
major=["Statistics"], year="3",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] Career Switcher: {score}")
self.assertGreaterEqual(score, 50.0)
[docs]
def test_graduate_school_prep(self):
mentee = Profile(
hobbies="quantum computing, physics research, reading papers",
goals="I'm a junior physics student planning to apply to quantum computing PhD programs.",
clubs="Physics research group, grad school prep",
major=["Physics"], year="3",
)
mentor = Profile(
hobbies="quantum physics, research, graduate school applications",
goals="I'm heading to MIT for a quantum computing PhD and want to help with grad applications.",
clubs="Physics mentorship, research lab",
major=["Physics"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Real World] Grad School Prep: {score}")
self.assertGreaterEqual(score, 68.0)
[docs]
class TestFieldSpecificScenarios(unittest.TestCase):
[docs]
def setUp(self):
from matching.scoring import calculate_match_score
self.calculate_match_score = calculate_match_score
[docs]
def test_frontend_vs_backend_developer(self):
mentee = Profile(
hobbies="React, CSS, design, frontend development",
goals="I want to create beautiful user interfaces and web experiences.",
clubs="Web dev club, design club",
major=["Computer Science"], year="2",
)
mentor = Profile(
hobbies="databases, APIs, system design, backend engineering",
goals="I specialize in backend systems and want to mentor students in that area.",
clubs="CS club, open source contributors",
major=["Computer Science"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Field] Frontend vs Backend: {score}")
self.assertGreaterEqual(score, 45.0)
self.assertLessEqual(score, 80.0)
[docs]
def test_theoretical_vs_applied_math(self):
mentee = Profile(
hobbies="pure mathematics, proofs, abstract algebra, number theory",
goals="I want to study abstract algebra and pursue theoretical mathematics.",
clubs="Math club, problem solving group",
major=["Mathematics"], year="2",
)
mentor = Profile(
hobbies="applied math, machine learning, optimization, Python",
goals="I work on applied math problems in ML and optimization.",
clubs="Applied math group, data science club",
major=["Mathematics"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Field] Theoretical vs Applied Math: {score}")
self.assertGreaterEqual(score, 40.0)
self.assertLessEqual(score, 70.0)
[docs]
def test_creative_writing_vs_journalism(self):
mentee = Profile(
hobbies="creative writing, novels, poetry, literature",
goals="I'm an English major passionate about writing fiction.",
clubs="Creative writing club, literary magazine",
major=["English"], year="1",
)
mentor = Profile(
hobbies="journalism, news writing, investigative reporting",
goals="I'm an English major focused on journalism and news media.",
clubs="Daily Bruin, journalism club",
major=["English"], year="3",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Field] Creative Writing vs Journalism: {score}")
self.assertGreaterEqual(score, 45.0)
[docs]
class TestEdgeCaseProfiles(unittest.TestCase):
[docs]
def setUp(self):
from matching.scoring import build_profile_text, calculate_match_score
self.calculate_match_score = calculate_match_score
self.build_profile_text = build_profile_text
[docs]
def test_very_brief_vs_detailed_profiles(self):
mentee = Profile(hobbies="coding", goals="CS major", major=["Computer Science"], year="1")
mentor = Profile(
hobbies="web development, machine learning, open source, software engineering",
goals="Senior CS major with experience at Google and Facebook. Want to mentor students into software engineering.",
clubs="CS mentorship, open source club",
major=["Computer Science"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Edge] Brief vs Detailed: {score}")
self.assertGreaterEqual(score, 40.0)
[docs]
def test_interdisciplinary_double_major(self):
mentee = Profile(
hobbies="AI ethics, philosophy of mind, machine learning",
goals="Double major in CS and Philosophy. Interested in AI ethics and consciousness.",
clubs="AI ethics club, philosophy society",
major=["Computer Science", "Philosophy"], year="2",
)
mentor = Profile(
hobbies="technology ethics, AI, philosophy, computer science",
goals="CS major fascinated by the ethical implications of technology.",
clubs="Ethics in tech, CS club",
major=["Computer Science"], year="4",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Edge] Interdisciplinary Double Major: {score}")
self.assertGreaterEqual(score, 65.0)
[docs]
def test_all_generic_interests(self):
mentee = Profile(
hobbies="reading, music, sports, travel",
goals="I like learning new things and meeting people.",
major=[], year="1",
)
mentor = Profile(
hobbies="books, concerts, exercise, adventures",
goals="I enjoy helping others and exploring new opportunities.",
major=[], year="3",
)
score = self.calculate_match_score(mentee, mentor)
print(f"\n[Edge] Generic Interests: {score}")
self.assertGreaterEqual(score, 20.0)
self.assertLessEqual(score, 70.0)
[docs]
def test_special_category_max_cap(self):
"""4 shared categories should add exactly 20 points."""
mentee = Profile(
hobbies="engineering", goals="engineering career",
major=["Engineering"], year="1",
international=True, commuter=True, firstgen=True, transfer=True,
)
mentor = Profile(
hobbies="engineering", goals="engineering career",
major=["Engineering"], year="3",
international=True, commuter=True, firstgen=True, transfer=True,
)
mentee2 = Profile(hobbies="engineering", goals="engineering career", major=["Engineering"], year="1")
mentor2 = Profile(hobbies="engineering", goals="engineering career", major=["Engineering"], year="3")
score_with = self.calculate_match_score(mentee, mentor)
score_without = self.calculate_match_score(mentee2, mentor2)
print(f"\n[Edge] Category cap — with: {score_with}, without: {score_without}")
self.assertAlmostEqual(score_with - score_without, 20.0, places=1)
[docs]
def test_minor_field_included_in_profile_text(self):
"""Minor should appear in the combined profile text."""
user = Profile(
hobbies="coding", goals="software engineer",
major=["Computer Science"], minor=["Mathematics"],
)
text = self.build_profile_text(user)
self.assertIn("Mathematics", text)
self.assertIn("Computer Science", text)
if __name__ == '__main__':
unittest.main(verbosity=2)