Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    12
    Rep Power
    0

    My If Statements Aren't Catching What They Should


    I am trying to implement a dating agency system for my university project. The section I have been allocated to do is to search for a partner that matches a user. We have preset data so that it allows us to test the system is working, however it doesn't seem to be for me.

    The very first check that I make is that the sexual orientation of a user and their gender matches up with that of the record being checked, but in one case this check doesn't seem to be working.

    One of the preset users is a heterosexual female, another is a bisexual female. These two users do not match because the first user does not want a partner of the same sex, however the system is matching these two up.

    Could you please look at my code and help me identify where the problem is? I have been spending about the last hour and a half trying to work out why it isn't working but I can't figure it out. I have traced through the method I use, using these two users as my data and it seems to me as if it should be working.

    The following is the method used to search for a matching partner, as I said, it seems to be the very first if statement that the problem is with because in the case of these 2 users, it is falling at the first hurdle.

    Code:
    public int searchForPartner()
    	{	int count = 0;
    		boolean found = false;
    		int currentUser = Person.getCurrentUser();
    		
    		do
    		{	if (users[count] == null || count == currentUser)
    				count++;
    			else if (compareSexualOrientations(count))
    				{	if (compareAges(count))
    					{	if (compareLocations(count))
    						{	if (compareMaritalStatuses(count))
    							{	if (compareSmokes(count))
    								{	if (compareInterests(count))
    										found = true;
    									else
    										count++;
    								}//compareSmokes if
    								else
    									count++;
    							}//compareMaritalStatuses if
    							else
    								count++;
    						}//compareLocations if
    						else
    							count++;
    					}//compareAges if
    					else
    						count++;
    				}//compareSexualOrienatations if
    				else
    					count++;
    		}while (!found && count < users.length);
    		
    		return count;
    	}//searchForPartner
    The following is then the compareSexualOrientations method (the sexual orientations are strings and the genders are characters):

    Code:
    public boolean compareSexualOrientations(int pCount)
    	{	//A method to find out whether two users are a match based on their sexual orientation and genders
    		if (users[currentUser].getSexualOrientation().equals("Heterosexual") && users[currentUser].getGender() != users[pCount].getGender())
    		{	if (users[pCount].getSexualOrientation().equals("Heterosexual") || users[pCount].getSexualOrientation().equals("Bisexual"))
    				return true;
    		}
    		
    		if (users[currentUser].getSexualOrientation().equals("Homosexual") && users[currentUser].getGender() == users[pCount].getGender())
    		{	if (users[pCount].getSexualOrientation().equals("Homosexual") || users[pCount].getSexualOrientation().equals("Bisexual"))
    				return true;			
    		}
    		
    		if (users[currentUser].getSexualOrientation().equals("Bisexual") && users[pCount].getSexualOrientation().equals("Bisexual"))
    			return true;
    		else if (users[pCount].getSexualOrientation().equals("Heterosexual") && users[currentUser].getGender() != users[pCount].getGender())
    				return true;
    			else if (users[pCount].getSexualOrientation().equals("Homosexual") && users[currentUser].getGender() == users[pCount].getGender())
    				return true;
    		
    		return false;
    }//compareSexualOrientations
    Thanks to anybody who can help me.

    David
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6467
    Start by outputting data either to the console, or a log file, just before each of the if statements to see if the data is in fact what you think it should be.

    Any reason you're not using a database to do this work for you, simply build a query, and let the database do all the hard work?
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    12
    Rep Power
    0
    Thanks, I will try printing to the console and see what it comes up with.

    Unfortunately we can't make a database for this because it's a software development module and we have been told we have to create it using swing. It would make life so much easier to do it in a database but unfortunately life isn't always easy
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,625
    Rep Power
    6089
    Your IFs are crazy. Use && instead of all those ifs.
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2007
    Posts
    16
    Rep Power
    0
    try the pen and paper method. input some data into your program and c what it gives. then do the same thing but manually. print the code out and use the same data to go through your code. you'll prolly find the problem.


    best thing would be to rewrite your code in a less complex form though by using operators (|| && )
  10. #6
  11. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    Besides the fact that your code does need some serious refactoring, the logic of compareSexualOrientations, although not very efficient, works.
    Did you print the gender and orientations in the console? My guess is that you're not comparing the two persons that you think you are.

    To refactor your compareSexualOrientations method you first describe it's logic in plain English:
    If two persons are of the same gender and both are not of heterosexual orientation, they match. If two persons are of different gender and both are not of homosexual orientation they match.
    We could translate this to Java lik ethis:[hl=java]//It's always good to use constants in situations like this
    static final String HETEROSEXUAL = "Heterosexual";
    static final String HOMOSEXUAL = "Homosexual";
    static final String BISEXUAL = "Bisexual";

    public boolean compareSexualOrientations(int pCount) {
    boolean match = false;
    //Some will probably object to the following style.
    //In cases where performance is not a big issue and
    //the possible values allow it, I think it is an easy
    //way to avoid endless if statements.
    String orientations = users[currentUser].getSexualOrientation()+users[pCount].getSexualOrientation();

    if ((users[currentUser].getGender() == users[pCount].getGender() &&
    orientations.indexOf(HETEROSEXUAL) == -1) ||
    (users[currentUser].getGender() != users[pCount].getGender() &&
    orientations.indexOf(HOMOSEXUAL) == -1)) {
    match = true;
    }
    //Single exit point, always nice
    return match;
    }
    [/hl]Another (more preferable IMO) way would be to make the matching process part of the User, Person, or WhateverYouCalledIt class that is in the user array. The same logic as above still applies though.

    Comments on this post

    • jzd agrees
    Last edited by wsa1971; March 27th, 2007 at 06:37 AM. Reason: Had some time to kill
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  12. #7
  13. No Profile Picture
    rebel with a cause
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2004
    Location
    The Batsh!t Crazy State.
    Posts
    5,814
    Rep Power
    3466
    Originally Posted by gibson149
    Unfortunately we can't make a database for this because it's a software development module and we have been told we have to create it using swing. It would make life so much easier to do it in a database but unfortunately life isn't always easy
    That makes no sense. Swing is just a gui development library. The application can be written to use swing for display and still draw information from a database through JDBC. Are you sure you understood the requirements correctly?

    Comments on this post

    • Axweildr agrees
    Dear God. What is it like in your funny little brains? It must be so boring.
  14. #8
  15. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Another (more preferable IMO) way would be to make the matching process part of the User, Person, or WhateverYouCalledIt class that is in the user array.
    Indeed. In order to properly leverage encapsulation, one should let the User/Person/WhateverYouCalledIt object tell you whether or not it's compatible with another user rather than evaluating that logic externally. For example, the User/Person/WhateverYouCalledIt should implement a method along the lines of the following:
    Code:
    public boolean isSexuallyCompatible(Person p) { /* ... */ }
    Example:
    Java Code:
    package yawmark.devshed.matchmaker;
     
    import static org.junit.Assert.*;
     
    import org.junit.Before;
    import org.junit.Test;
     
     
    public class PersonTest {
     
    	private static final Person BISEXUAL = new Person(SexualOrientation.BI);
    	private static final Person HOMOSEXUAL = new Person(SexualOrientation.HOMO);
    	private static final Person HETEROSEXUAL = new Person(SexualOrientation.HETERO);
     
    	@Before
    	public void setUp() throws Exception {
    	}
     
    	@Test
    	public void testHeteroCompatibility() throws Exception {
    		Person p = HETEROSEXUAL;
    		assertTrue("Heteros compatible with other heteros", p.isCompatible(HETEROSEXUAL));
    		assertFalse("Heteros incompatible with homos", p.isCompatible(HOMOSEXUAL));
    		assertTrue("Heteros compatible with bis", p.isCompatible(BISEXUAL));
    	}
     
    	@Test 
    	public void testHomoCompatibility() throws Exception {
    		Person p = HOMOSEXUAL;
    		assertTrue("Homos compatible with homos", p.isCompatible(HOMOSEXUAL));
    		assertFalse("Homos compatible with heteros", p.isCompatible(HETEROSEXUAL));
    		assertTrue("Homos compatible with bis", p.isCompatible(BISEXUAL));
    	}
     
    	@Test
    	public void testBiCompatibility() throws Exception {
    		Person p = BISEXUAL;
    		assertTrue("Bis compatible with everyone",
    				p.isCompatible(BISEXUAL) &&
    				p.isCompatible(HETEROSEXUAL) &&
    				p.isCompatible(HOMOSEXUAL)
    	    );
    	}
    }

    That's the test, and here's the class:
    Java Code:
    package yawmark.devshed.matchmaker;
     
    public class Person {
     
    	private SexualOrientation sexualOrientation;
     
    	public Person(SexualOrientation s) {
    		this.sexualOrientation = s;
    	}
     
    	public boolean isCompatible(Person person) {
    		return (this.sexualOrientation == SexualOrientation.BI)
    				|| (person.sexualOrientation == SexualOrientation.BI)
    				|| (this.sexualOrientation == person.sexualOrientation);
    	}
     
    }
     
    enum SexualOrientation {
    	HETERO, HOMO, BI
    }

    The logic of whether or not one person is compatible with another should reside in the Person class. Think about it: if I want to know who you're compatible with, I should ask *you*, not someone else, right?

    Using good object-oriented programming practices will help make your code less brittle.

    ~

    Comments on this post

    • wsa1971 agrees : Nice code, but... (see below)
    Last edited by Yawmark; March 27th, 2007 at 07:35 AM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  16. #9
  17. AYBABTU
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Here or There
    Posts
    1,256
    Rep Power
    380
    @Yawmark: You do realise that your (otherwise excellent) example will match a lesbian female with a gay man (and a bisexual male to a heterosexual male etc...), right?

    Originally Posted by Yawmark
    The logic of whether or not one person is compatible with another should reside in the Person class. Think about it: if I want to know who you're compatible with, I should ask *you*, not someone else, right?
    You should, but in the real world a lot of people do exactly the opposite.
    Last edited by wsa1971; March 27th, 2007 at 07:47 AM.
    A common mistake people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
    Douglas Adams
  18. #10
  19. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    @Yawmark: You do realise that your (otherwise excellent) example will match a lesbian female with a gay man (and a bisexual male to a heterosexual male etc...), right?
    Doh! I was trying to emphasize encapsulation, *not* the business logic. I'll be happy to edit it later.
    You should, but in the real world a lot of people do exactly the opposite.
    A lot of people aren't very good object-oriented programmers, then.

    ~
    Last edited by Yawmark; March 27th, 2007 at 12:31 PM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  20. #11
  21. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Okay, here's some slightly less embarassing business logic, with a *big* caveat: More complex "compatibility" requirements will -- obviously -- require a more complex algorithm, which should likely be encapsulated in its own class; e.g., a CompatibilityStrategy or some such thing.

    The test:
    Java Code:
    package yawmark.devshed.matchmaker;
     
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.assertTrue;
     
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
     
    import org.junit.Before;
    import org.junit.Test;
     
    public class PersonTest {
     
    	private static final Person BISEXUAL_MALE = new Person(SexualOrientation.BI, Gender.MALE);
    	private static final Person BISEXUAL_FEMALE = new Person(SexualOrientation.BI, Gender.FEMALE);
    	private static final Person HOMOSEXUAL_MALE = new Person(SexualOrientation.HOMO, Gender.MALE);
    	private static final Person HOMOSEXUAL_FEMALE = new Person(SexualOrientation.HOMO, Gender.FEMALE);
    	private static final Person HETEROSEXUAL_MALE = new Person(SexualOrientation.HETERO, Gender.MALE);
    	private static final Person HETEROSEXUAL_FEMALE = new Person(SexualOrientation.HETERO, Gender.FEMALE);
     
    	private List<Person> potentialMatches;
     
    	@Before
    	public void setUp() throws Exception {
    		this.potentialMatches = new ArrayList<Person>(Arrays.asList(BISEXUAL_MALE, BISEXUAL_FEMALE,
    				HOMOSEXUAL_MALE, HOMOSEXUAL_FEMALE, HETEROSEXUAL_MALE, HETEROSEXUAL_FEMALE));
    	}
     
    	@Test
    	public void testMaleHeteroCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HETEROSEXUAL_FEMALE, BISEXUAL_FEMALE);
    		checkMatches(HETEROSEXUAL_MALE, matches);
     
    	}
     
    	@Test
    	public void testFemaleHeteroCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HETEROSEXUAL_MALE, BISEXUAL_MALE);
    		checkMatches(HETEROSEXUAL_FEMALE, matches);
    	}
     
    	@Test
    	public void testMaleHomoCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HOMOSEXUAL_MALE, BISEXUAL_MALE);
    		checkMatches(HOMOSEXUAL_MALE, matches);
    	}
     
    	@Test
    	public void testFemaleHomoCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HOMOSEXUAL_FEMALE, BISEXUAL_FEMALE);
    		checkMatches(HOMOSEXUAL_FEMALE, matches);
    	}
     
    	@Test
    	public void testMaleBiCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HOMOSEXUAL_MALE, HETEROSEXUAL_FEMALE, BISEXUAL_MALE, BISEXUAL_FEMALE);
    		checkMatches(BISEXUAL_MALE, matches);
    	}
     
    	@Test
    	public void testFemaleBiCompatibility() throws Exception {
    		List<Person> matches = Arrays.asList(HETEROSEXUAL_MALE, HOMOSEXUAL_FEMALE, BISEXUAL_MALE, BISEXUAL_FEMALE);
    		checkMatches(BISEXUAL_FEMALE, matches);
    	}
     
    	private void checkMatches(Person p, List<Person> matches) {
    		for (Person match : matches) {
    			assertTrue(String.format("%s should be compatible with %s", p, match), p.isCompatible(match));
    		}
    		assertTrue(this.potentialMatches.removeAll(matches));
    		for (Person nonMatch : potentialMatches) {
    			assertFalse(String.format("%s should not be compatible with %s", p, nonMatch), p.isCompatible(nonMatch));
    		}
    	}
    }


    The class:
    Java Code:
    package yawmark.devshed.matchmaker;
     
    public class Person {
     
    	private SexualOrientation sexualOrientation;
    	private Gender gender;
     
    	public Person(SexualOrientation s, Gender gender) {
    		this.sexualOrientation = s;
    		this.gender = gender;
    	}
     
    	public boolean isCompatible(Person other) {
    		switch (this.sexualOrientation) {
    			case BI: 	 return (this.gender == other.gender) 
    								? (other.sexualOrientation != SexualOrientation.HETERO) 
    								: (other.sexualOrientation != SexualOrientation.HOMO);
    			case HETERO: return (this.gender != other.gender) && (other.sexualOrientation != SexualOrientation.HOMO);
    			case HOMO:   return (this.gender == other.gender) && (other.sexualOrientation != SexualOrientation.HETERO);
    			default:     return false;
    		}
    	}
     
    	public String toString() {
    		return String.format("[%s %s]", this.sexualOrientation, this.gender);
    	}
     
    }
     
    enum SexualOrientation {
    	HETERO, HOMO, BI
    }
     
    enum Gender {
    	MALE, FEMALE
    }


    Ah, the joys of TDD. Feel free to post improvements that pass the test case; I'm sure there are many to be made!

    ~
    Last edited by Yawmark; March 27th, 2007 at 10:11 AM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  22. #12
  23. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2005
    Location
    Internet
    Posts
    7,625
    Rep Power
    6089
    Hmm. I would just use 0, 1, and 2 for preference. 0 = guys, 1 = both, 2 = girls. I think you overcomplicated it.
    Chat Server Project & Tutorial | WiFi-remote-control sailboat (building) | Joke Thread
    Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.
    Use XXX in a comment to flag something that is bogus but works. Use FIXME to flag something that is bogus and broken. Use TODO to leave yourself reminders. Calling a program finished before all these points are checked off is lazy.
    -Partial Credit: Sun

    If I ask you to redescribe your problem, it's because when you describe issues in detail, you often get a *click* and you suddenly know the solutions.
    Ches Koblents
  24. #13
  25. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Hmm. I would just use 0, 1, and 2 for preference. 0 = guys, 1 = both, 2 = girls. I think you overcomplicated it.
    So we're still on the business logic, eh? I think using a simple preference oversimplifies the situation. A bisexual female may prefer a heterosexual female, but that preference is not likely to be reciprocated (this problem is mentioned in the OP). If you're hoping to determine compatibility, you'll need to look at both sides of the aisle, so to speak. I found that to be pretty complicated, actually. If there's a way to evaluate compatibility based solely on the preference of one particular side of the matchup, I don't see it.

    But all this misses the point. The gist of my posts (in support of wsa1971's design suggestion) is that this logic belongs within the object that contains the data rather than asking an object for its data. That's the whole principle of encapsulation and data hiding. By encapsulating the logic this way, the implementation details are irrelevant to callers. You can use enums, strings, int values, or whatever to determine compatibility, and client code never has to change. Exposing int values for compatability calculations is a very brittle, highly-coupling solution.

    ~
    Last edited by Yawmark; March 27th, 2007 at 12:18 PM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  26. #14
  27. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    I would just use 0, 1, and 2 for preference. 0 = guys, 1 = both, 2 = girls. I think you overcomplicated it.
    Back on the business logic...

    If you're feeling up to it, here is a unit test (JUnit 4):
    Java Code:
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.assertTrue;
     
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
     
    import org.junit.Before;
    import org.junit.Test;
     
    public class MatchMakerCandidateTest {
     
    	private static final MatchMakerCandidateFactory CANDIDATE_FACTORY = new PersonMatchMakerCandidateFactory(); // replace with your own implementation
     
    	private static final MatchMakerCandidate BISEXUAL_MALE = CANDIDATE_FACTORY.createCandidate("bisexual male");
    	private static final MatchMakerCandidate BISEXUAL_FEMALE = CANDIDATE_FACTORY.createCandidate("bisexual female");
    	private static final MatchMakerCandidate HOMOSEXUAL_MALE = CANDIDATE_FACTORY.createCandidate("homosexual male");
    	private static final MatchMakerCandidate HOMOSEXUAL_FEMALE = CANDIDATE_FACTORY.createCandidate("homosexual female");
    	private static final MatchMakerCandidate HETEROSEXUAL_MALE = CANDIDATE_FACTORY.createCandidate("heterosexual male");
    	private static final MatchMakerCandidate HETEROSEXUAL_FEMALE = CANDIDATE_FACTORY.createCandidate("heterosexual female");
     
    	private List<MatchMakerCandidate> potentialMatches;
     
    	@Before
    	public void setUp() throws Exception {
    		this.potentialMatches = new ArrayList<MatchMakerCandidate>(Arrays.asList(BISEXUAL_MALE, BISEXUAL_FEMALE,
    				HOMOSEXUAL_MALE, HOMOSEXUAL_FEMALE, HETEROSEXUAL_MALE, HETEROSEXUAL_FEMALE));
    	}
     
    	@Test
    	public void testMaleHeteroCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HETEROSEXUAL_FEMALE, BISEXUAL_FEMALE);
    		checkMatches(HETEROSEXUAL_MALE, matches);
     
    	}
     
    	@Test
    	public void testFemaleHeteroCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HETEROSEXUAL_MALE, BISEXUAL_MALE);
    		checkMatches(HETEROSEXUAL_FEMALE, matches);
    	}
     
    	@Test
    	public void testMaleHomoCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HOMOSEXUAL_MALE, BISEXUAL_MALE);
    		checkMatches(HOMOSEXUAL_MALE, matches);
    	}
     
    	@Test
    	public void testFemaleHomoCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HOMOSEXUAL_FEMALE, BISEXUAL_FEMALE);
    		checkMatches(HOMOSEXUAL_FEMALE, matches);
    	}
     
    	@Test
    	public void testMaleBiCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HOMOSEXUAL_MALE, HETEROSEXUAL_FEMALE, BISEXUAL_MALE, BISEXUAL_FEMALE);
    		checkMatches(BISEXUAL_MALE, matches);
    	}
     
    	@Test
    	public void testFemaleBiCompatibility() throws Exception {
    		List<MatchMakerCandidate> matches = Arrays.asList(HETEROSEXUAL_MALE, HOMOSEXUAL_FEMALE, BISEXUAL_MALE, BISEXUAL_FEMALE);
    		checkMatches(BISEXUAL_FEMALE, matches);
    	}
     
    	private void checkMatches(MatchMakerCandidate p, List<MatchMakerCandidate> matches) {
    		for (MatchMakerCandidate match : matches) {
    			assertTrue(String.format("%s should be compatible with %s", p, match), p.isCompatible(match));
    		}
    		assertTrue(this.potentialMatches.removeAll(matches));
    		for (MatchMakerCandidate nonMatch : potentialMatches) {
    			assertFalse(String.format("%s should not be compatible with %s", p, nonMatch), p.isCompatible(nonMatch));
    		}
    	}
    }

    Here are the interfaces:
    Java Code:
    public interface MatchMakerCandidate {
     
    	boolean isCompatible(MatchMakerCandidate candidate);
     
    }
     
    public interface MatchMakerCandidateFactory {
     
    	MatchMakerCandidate createCandidate(String description);
     
    }

    I'd like to see what you come up with for an implementation using the int value preferences you described. I may be missing something, and if so, I'd like to be shown where.

    Cheers!

    ~
    Last edited by Yawmark; March 27th, 2007 at 12:10 PM.
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  28. #15
  29. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    P.S. One may well wish to extend the test for the condition that a MatchMakerCandidate is or is not sexually compatible with itself. It all depends on the business requirements, of course...

    ~

    Comments on this post

    • Axweildr agrees : I *really* want to see that written up in a "Business Proposal" ;)
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo