Opened 8 years ago

Closed 8 years ago

#379 closed defect (fixed)

Fix validation of requirements to check for unit

Reported by: ibboard Owned by:
Priority: critical Milestone: WarFoundry API 0.2
Component: WarFoundry-API Version: Trunk
Keywords: requirement army validation Cc:
Blocked By: Blocking:

Description

Before #350, the first two unit requirements have been written and have unit tests, but the tests are making assumptions that mean they don't test for the correct stand-alone behaviour.

Currently, an "army valid" test that has a "must not have more than X of unit type A" requirement from a unit type B that is in the race but not in the army would result in a failed test, even though it should be NotApplicable because unit type B isn't in the army.

Change History (31)

comment:1 Changed 8 years ago by ibboard

Status: newconfirmed

comment:2 Changed 8 years ago by ibboard

While working on #350, I realised that this was partly by design (albeit a slightly bad design). The existing requirements were meant as generic requirements that could be used on anything (not just units). The factories then tied them to unit types. The behaviour still needs correcting, but the design should keep the existing requirements as generic (or make them abstract) and create unit-specific versions.

comment:3 Changed 8 years ago by IBBoard <dev@…>

In [676f5ce041768b3fbef71ed3f9cced098269fd07/IBBoard.WarFoundry.API]:

Re #379: Fix validation of requirements to check for unit

  • Add method to Army to differentiate "all requirements" from "requirements relevant to adding a unit"

comment:4 Changed 8 years ago by IBBoard <dev@…>

In [ea104de9189e7ca6e4dc6d8b245cbb04fadc59e3/IBBoard.WarFoundry.API.Tests]:

Re #379: Fix validation of requirements to check for unit

  • Add tests for new method in Army to get just adding-relevant requirements

comment:5 Changed 8 years ago by IBBoard <dev@…>

In [b671085871b7bb15f2f938d51736cf632ea9af05/IBBoard.WarFoundry.API]:

Re #379: Fix validation of requirements to check for unit

  • Separate messages for adding unit and validating army.
  • Make translation easier (once we add it in)

comment:6 Changed 8 years ago by IBBoard <dev@…>

In [dace3b7779cab56e2e5b6241eb27185ea6f2dbf6/IBBoard.WarFoundry.API]:

Re #379: Fix validation of requirements to check for unit

  • Restructure all validation messages to a common base system that will translate better
  • Update "No More Than" texts to differentiate two contexts (adding and validating)

comment:7 Changed 8 years ago by IBBoard <dev@…>

In [d39682a98adf6de1632568db6fb2bed57368a265/IBBoard.WarFoundry.API.Tests]:

Re #379: Fix validation of requirements to check for unit

  • Add unit tests for army object
  • Update tests that check the message

comment:8 Changed 8 years ago by IBBoard <dev@…>

In [78ba834cb1f74d5d54b3e6e0926fd76daf4078a8/IBBoard.WarFoundry.API.Tests]:

Re #379: Fix validation of requirements to check for unit

  • Fix expected text for "Requires no more than", which has a slightly different format

comment:9 Changed 8 years ago by IBBoard <dev@…>

In [def5d333c5e82daaf27406a4ef363c9d2f59d400/IBBoard.WarFoundry.API]:

Re #379: Fix validation of requirements to check for unit

  • Remove custom messages for overrides to reduce verbosity
  • Add missing multiplication signs for readability

comment:10 Changed 8 years ago by IBBoard <dev@…>

In [27f163bf884a7a43b8c23323b6790e1cca7cf10a/IBBoard.WarFoundry.API.Tests]:

Re #379: Fix validation of requirements to check for unit

  • Update checked text to match new, cleaner text

comment:11 Changed 8 years ago by ibboard

Todo:

  • RequiresNUnitsForMUnitsRequirement renamed to UnitRequiresNUnitsForMUnits to match existing pattern
  • Extract common RequiresNUnitsForMObjectsRequirement
  • Give Unit... requirements their own ID (currently got parent type's static value cascading through)
  • Make better use of IsApplicable, which is in abstract class but is currently ignored in most requirements

comment:12 Changed 8 years ago by IBBoard <dev@…>

In afc6410e4efc75696abcb1f4e755712443bda60b/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Move to "Unit" requirements, since we assume things depend on units
  • Rename some classes to more meaningful names from unit-based change
  • Rename "requires N for M" requirement as we can make it more flexible

comment:13 Changed 8 years ago by IBBoard <dev@…>

In 52baffdd2ab9beb829f441b4ec928d61a070ea90/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Default to not being applicable - make requirements say when they are
  • Fix UnitRequiresNUnitsForMUnitsRequirement to not be applicable when adding unrelated units (even if army itself fails the rule)
  • Fix type casting issues in equality check

comment:14 Changed 8 years ago by IBBoard <dev@…>

In 8e01c3174cc34758b343cb92d01da34ba905b48c/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Rename public accessor for unit types to ConstraintTypes so that "no more than" requirements don't work with "required types"
  • Remove class level version of ConstraintTypes to fall back to abstract class version
  • Make sure we cascade allowedObject up through RequiresNoMoreThanNOfUnitTypeRequirement
  • Rebuild UnitRequiresNoMoreThanNOfUnitTypeRequirement "IsApplicable" so that we don't get applicable for unrelated types, even if the requirement is currently in a failure state

comment:15 Changed 8 years ago by IBBoard <dev@…>

In 680db2462e34827b3b21e87fb364b4e25a2f687e/IBBoard.WarFoundry.API:

Re #379:

  • Move GetObjectCountFromArmy(Army, OBJECT_TYPE) to top level and implement
  • Fix army validation for appropriate "NA" returns
  • Make basic "Requires..." requirements abstract so that we always need to make specific versions (e.g. UnitRequires... that knows how to check amount of units)

comment:16 Changed 8 years ago by IBBoard <dev@…>

In 7a00aeba3d2ffea552d371a14de42b08bdcfefeb/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Re-add requirement for handling numbers of units in an army

comment:17 Changed 8 years ago by IBBoard <dev@…>

In 025319b6fa7a0abce65dc1e1d4377f75635b3ae4/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Create max count requirement object
  • Re-add code for min/max counts as requirements

comment:18 Changed 8 years ago by IBBoard <dev@…>

In f0594621e4a0c7b450eca443e78950b03882a60e/IBBoard.WarFoundry.API:

Re #379: Fix validation of requirements to check for unit

  • Move "Is applicable" checks up to abstract "no more than N of unit type" class

comment:19 Changed 8 years ago by IBBoard <dev@…>

In 159dc9be36c285a588dacafeae158b1e433bb31d/IBBoard.WarFoundry.API:

Re #379: Fix requirements

  • Move equality and hashcode up to AbstractUnitRequirement for consistency

comment:20 Changed 8 years ago by IBBoard <dev@…>

In c323770e61c2537ff4be7c95eb33ae769d596e98/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Rename classes in tests to match API changes
  • Alter tests to match new API (all classes require at least one UnitType that they're relevant to now)

comment:21 Changed 8 years ago by IBBoard <dev@…>

In fc9a90d29ae067a7ce74675bcf02675f6fb5deaf/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Fix some of the copy-and-paste errors in the tests - some tests still fail

comment:22 Changed 8 years ago by IBBoard <dev@…>

In 649759343da5537cbdb3c1fad88e2b33d66d562a/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Tidy up tests to reduce replication and fix copy-and-paste inconsistencies

comment:23 Changed 8 years ago by IBBoard <dev@…>

In bc782a0d47bf947a672add6da0dde6212308bd94/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Finish off validation tests for "N units for M Units" requirement

comment:24 Changed 8 years ago by IBBoard <dev@…>

In 325943cb1db0ad1f5f680664623ed2e47f0ec14c/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Create common base class for requirement testing with helper methods
  • Rework unit adding tests in UnitRequiresNoMoreThanNOfUnitTypeRequirementTest to new structure

comment:25 Changed 8 years ago by IBBoard <dev@…>

In 0416df2ab39b891446bfb2a3d0ca2d6339623f7b/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Add army validation tests for UnitRequiresNoMoreThanNOfUnitTypeRequirementTest

TODO: one test broken (should be NA, not Passed)

comment:26 Changed 8 years ago by IBBoard <dev@…>

In 1674a499168e448fd8712817c6c826787fb0ab31/IBBoard.WarFoundry.API.Tests:

Re #379:

  • Make all tests test both Unit and UnitType by modifying abstract class's helper methods
  • Re-implement UnitRequiresAtLeastNUnitsRequirementTest tests (adding and validation)
  • Remove unused tests from Requires...

TODO: Re-implement equality testing

comment:27 Changed 8 years ago by IBBoard <dev@…>

In 7e7296c0ae1ff94f98b5de9ae13ea77896a85ea3/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Add tests for requiring minimum number of units in army

comment:28 Changed 8 years ago by IBBoard <dev@…>

In 442bcf7306b9d52af9a3bfefd930edd6d8b3a9d7/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Add tests for max limit on units in army
  • Re-add code for unit type requirement checking with min/max limits

comment:29 Changed 8 years ago by IBBoard <dev@…>

In 9bf34e88da89ea5d38db606533c1226608fbb392/IBBoard.WarFoundry.API.Tests:

Re #379: Fix validation of requirements to check for unit

  • Add equality tests to try to resolve UnitType tests for limits as requirements
  • Ensure consistency with extra layer in hierarchy

comment:30 Changed 8 years ago by IBBoard <dev@…>

In d60d93b787dcc11e8f5e61da5641f8b5c013ad76/IBBoard.WarFoundry.API.Tests:

Re #379: Fix requirements

  • Fix unit test - we had two limits in one requirement, not just one

comment:31 Changed 8 years ago by ibboard

Resolution: fixed
Status: confirmedclosed

Now completed (unless anyone complains it is broken).

Note: See TracTickets for help on using tickets.