Skip to content

Simplify tests #38

Description

@leesjensen

Several TAs were having trouble parsing the castling tests and the equality tests.

We should review these and see if they can be simplified.

   @Test
    @DisplayName("HashCode Testing")
    public void hashTest() {
        Assertions.assertEquals(original.hashCode(), equivalent.hashCode(),
                className + ".hashCode() returned different values for equivalent " + itemsPlural);
        for (var different : allDifferent) {
            Assertions.assertNotEquals(original.hashCode(), different.hashCode(),
                    className + ".hashCode() returned the same value for different " + itemsPlural);
        }
    }

    @Test
    @DisplayName("Equals & HashCode Testing")
    public void hashSetTest() {
        Set<T> set = new HashSet<>();
        set.add(original);

        // Manually test insertion of original & equal items
        Assertions.assertTrue(set.contains(original),
                "[" + className + "] Original item should exist in collection after adding original item");
        Assertions.assertTrue(set.contains(equivalent),
                "[" + className + "] Equivalent item should exist in collection after only adding original item");
        Assertions.assertEquals(1, set.size(),
                "[" + className + "] Collection should contain only 1 item after a single insert");
        set.add(equivalent);
        Assertions.assertEquals(1, set.size(),
                "[" + className + "] Collection should still contain only 1 item after adding equivalent item");

        // Programmatically test insertion of all different items
        int expectedSetSize = 1;
        for (var different : allDifferent) {
            Assertions.assertFalse(set.contains(different),
                    "[" + className + "] Different item should not be present in set before insertion");
            set.add(different);
            expectedSetSize++;
            Assertions.assertEquals(expectedSetSize, set.size(),
                    "[" + className + "] New item was counted as different during insertion");
        }

    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationrequirements:high changeThis code introduces a significant changes to the requirements for the project

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions