From 4bb9a201310df4ece48ddd2ead840047c70a71ac Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Mon, 21 Jul 2014 10:38:12 -0400 Subject: [PATCH] tests: introduces `test_prog` a program that build a fake documented model to test model related tools. Signed-off-by: Alexandre Terrasa --- tests/test_prog/README | 9 ++++ tests/test_prog/game/README | 2 + tests/test_prog/game/game.nit | 46 +++++++++++++++++++ tests/test_prog/platform/README | 2 + tests/test_prog/platform/platform.nit | 59 ++++++++++++++++++++++++ tests/test_prog/rpg/README | 2 + tests/test_prog/rpg/careers.nit | 70 +++++++++++++++++++++++++++++ tests/test_prog/rpg/character.nit | 69 ++++++++++++++++++++++++++++ tests/test_prog/rpg/combat.nit | 67 ++++++++++++++++++++++++++++ tests/test_prog/rpg/races.nit | 79 +++++++++++++++++++++++++++++++++ tests/test_prog/rpg/rpg.nit | 22 +++++++++ tests/test_prog/test_prog.nit | 27 +++++++++++ 12 files changed, 454 insertions(+) create mode 100644 tests/test_prog/README create mode 100644 tests/test_prog/game/README create mode 100644 tests/test_prog/game/game.nit create mode 100644 tests/test_prog/platform/README create mode 100644 tests/test_prog/platform/platform.nit create mode 100644 tests/test_prog/rpg/README create mode 100644 tests/test_prog/rpg/careers.nit create mode 100644 tests/test_prog/rpg/character.nit create mode 100644 tests/test_prog/rpg/combat.nit create mode 100644 tests/test_prog/rpg/races.nit create mode 100644 tests/test_prog/rpg/rpg.nit create mode 100644 tests/test_prog/test_prog.nit diff --git a/tests/test_prog/README b/tests/test_prog/README new file mode 100644 index 0000000..e71ce81 --- /dev/null +++ b/tests/test_prog/README @@ -0,0 +1,9 @@ +Test program for model tools. + +This program creates a fake model that can be used to test tools like: + +* `nitdoc` +* `nitmetrics` +* `nitx` +* or others `modelbuilder`. + diff --git a/tests/test_prog/game/README b/tests/test_prog/game/README new file mode 100644 index 0000000..8addc65 --- /dev/null +++ b/tests/test_prog/game/README @@ -0,0 +1,2 @@ +Gaming group + diff --git a/tests/test_prog/game/game.nit b/tests/test_prog/game/game.nit new file mode 100644 index 0000000..e7a7348 --- /dev/null +++ b/tests/test_prog/game/game.nit @@ -0,0 +1,46 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A game abstraction for RPG. +module game + +import rpg + +# This is the interface you have to implement to use ure gaming platform. +# +# see http://our.platform.com +interface Game + + # Characters played by human players. + fun player_characters: List[Character] is abstract + + # Characters players by computer. + fun computer_characters: List[Character] is abstract + + # Start the game. + # + # You have to implement that method! + fun start_game is abstract + + # Pause the game. + # + # You have to implement that method! + fun pause_game is abstract + + # Stop the game. + # + # You have to implement that method! + fun stop_game is abstract +end + diff --git a/tests/test_prog/platform/README b/tests/test_prog/platform/README new file mode 100644 index 0000000..1958baa --- /dev/null +++ b/tests/test_prog/platform/README @@ -0,0 +1,2 @@ +Fictive Crappy Platform. + diff --git a/tests/test_prog/platform/platform.nit b/tests/test_prog/platform/platform.nit new file mode 100644 index 0000000..d474ea0 --- /dev/null +++ b/tests/test_prog/platform/platform.nit @@ -0,0 +1,59 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Declares base types allowed on the platform. +module platform + +import end + +# Root of everything. +class Object + # Used for comparisons. + type OTHER: nullable Object + + # Is `other` equqls to `self`? + fun ==(other: OTHER): Bool is intern + + # Is `other` different from `self`? + fun !=(other: OTHER): Bool do return not self == other +end + +# Some services about Integers. +class Int + fun -: Int is intern + fun +(i: Int): Int is intern + fun -(i: Int): Int is intern + fun *(i: Int): Int is intern + fun /(i: Int): Int is intern + fun >(i: Int): Bool is intern + fun to_f: Float is intern +end + +# Some services about Floats. +class Float + fun +(f: Float): Float is intern + fun -(f: Float): Float is intern + fun *(f: Float): Float is intern + fun /(f: Float): Float is intern + fun >(f: Float): Bool is intern +end + +# Booleans, `true` or `false`. +class Bool end + +# Strings (there is no chars...). +class String end + +# List of things. +class List[E] end diff --git a/tests/test_prog/rpg/README b/tests/test_prog/rpg/README new file mode 100644 index 0000000..683bccc --- /dev/null +++ b/tests/test_prog/rpg/README @@ -0,0 +1,2 @@ +Role Playing Game group + diff --git a/tests/test_prog/rpg/careers.nit b/tests/test_prog/rpg/careers.nit new file mode 100644 index 0000000..deef5c9 --- /dev/null +++ b/tests/test_prog/rpg/careers.nit @@ -0,0 +1,70 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Careers of the game. +# +# All characters can have a `Career`. +# A character can also quit its current career and start a new one. +# +# Available careers: +# +# * `Warrior` +# * `Magician` +# * `Alcoholic` +module careers + +import platform + +# A `Career` gives a characteristic bonus or malus to the character. +abstract class Career + var strength_bonus: Int + var endurance_bonus: Int + var intelligence_bonus: Int + + init do end +end + +# Warriors are good for fighting. +class Warrior + super Career + + init do + self.strength_bonus = 10 + self.endurance_bonus = 10 + self.intelligence_bonus = 0 + end +end + +# Magicians know magic and how to use it. +class Magician + super Career + + init do + self.strength_bonus = -5 + self.endurance_bonus = 0 + self.intelligence_bonus = 20 + end +end + +# Alcoholics are good to nothing escept taking punches. +class Alcoholic + super Career + + init do + self.strength_bonus = -20 + self.endurance_bonus = 20 + self.intelligence_bonus = -40 + end +end + diff --git a/tests/test_prog/rpg/character.nit b/tests/test_prog/rpg/character.nit new file mode 100644 index 0000000..a494875 --- /dev/null +++ b/tests/test_prog/rpg/character.nit @@ -0,0 +1,69 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Characters are playable entity in the world. +module character + +import races +import careers + +# Characters can be played by both the human or the machine. +class Character + + # The `Race` of the character. + var race: Race + + # The current `Career` of the character. + # Returns `null` if character is unemployed. + var career: nullable Career writable = null + + fun quit do + career = null + end + + var name: String + var age: Int + var sex: Bool + + # The actual strength of the character. + # + # Returns `race.base_strength + career.strength_bonus` or just `race.base_strength` is unemployed. + fun total_strengh: Int do + if career != null then return race.base_strength + career.strength_bonus + return race.base_strength + end + + # The actual endurance of the character. + fun total_endurance: Int do + if career != null then return race.base_endurance + career.endurance_bonus + return race.base_endurance + end + + # The acutal intelligence of the character. + fun total_intelligence: Int do + if career != null then return race.base_intelligence + career.intelligence_bonus + return race.base_intelligence + end + + # Maximum health of the character. + # + # Based on `total endurance * 10`. + fun max_health: Int do return total_endurance * 10 + + # The current `health` of the character. + # + # Starts at `max_health`. + var health: Int = max_health +end + diff --git a/tests/test_prog/rpg/combat.nit b/tests/test_prog/rpg/combat.nit new file mode 100644 index 0000000..46462af --- /dev/null +++ b/tests/test_prog/rpg/combat.nit @@ -0,0 +1,67 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# COmbat interactions between characters. +module combat + +import character + +# Something that can be used to attack someone and inflict damage. +interface Weapon + # Damage per second inflicted by this weapon. + fun dps: Float is abstract +end + +# Something that can be combatted, it can `attack` and `defend`. +# +# World items can also be `Combatable`. +# `defend` method is then used to determines how the object react to an attack +# Some magical items can even `attack`. +interface Combatable + fun hit_points: Int is abstract + + # A `Combatable` can attack a `target` that is also a `Combatable`. + # + # Attack the `target` using `wepaon` and returns the number of inflicted hit points. + fun attack(target: Combatable, weapon: Weapon): Int is abstract + + # Like `attack` but cannot be defended. + fun direct_attack(target: Combatable, weapon: Weapon): Int is abstract + + # `Combatable` can defend against attacks. + # + # Defends against a number of received hit points and return the number of pared hit points. + # + # @param hit: damage received. + fun defend(hit: Int): Int is abstract + + # Is the character still have hit_points? + fun is_dead: Bool do return hit_points > 0 +end + +# Characters are now `Comabatable` +redef class Character + super Combatable + + # Use character `health` to determines hit_points. + redef fun hit_points do return health +end + +# Dwarves can be used as weapons. +redef class Dwarf + super Weapon + + # Dwarf `dps` are based on the dwarf `base_endurance` (represents weight here) + redef fun dps do return base_endurance.to_f / 10.0 +end diff --git a/tests/test_prog/rpg/races.nit b/tests/test_prog/rpg/races.nit new file mode 100644 index 0000000..9af0a00 --- /dev/null +++ b/tests/test_prog/rpg/races.nit @@ -0,0 +1,79 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Races of the game. +# +# All characters belong to a `Race`. +# +# Available races: +# +# * `Human` +# * `Dwarf` +# * `Elf` +module races + +import platform + +# Race determines basic characteristics and what the character will be able to do in life. +# +# These are base characteristics, they cannot be changed +# but you can add new ones if needed using refinement. +# Objects and spells cannot change those characteristics. +abstract class Race + + # Used to represents how strong the race is. + var base_strength: Int + + # Used to represents how the race can absorb damage. + var base_endurance: Int + + # Is this race smart? + var base_intelligence: Int + + init do end +end + +# Humans are able to do everithing. +class Human + super Race + + init do + self.base_strength = 50 + self.base_endurance = 50 + self.base_intelligence = 50 + end +end + +# Dwarves make strong warriors. +class Dwarf + super Race + + init do + self.base_strength = 60 + self.base_endurance = 50 + self.base_intelligence = 40 + end +end + +# Elves make good magicians. +class Elf + super Race + + init do + self.base_strength = 40 + self.base_endurance = 40 + self.base_intelligence = 70 + end +end + diff --git a/tests/test_prog/rpg/rpg.nit b/tests/test_prog/rpg/rpg.nit new file mode 100644 index 0000000..7356741 --- /dev/null +++ b/tests/test_prog/rpg/rpg.nit @@ -0,0 +1,22 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A worlg RPG abstraction. +module rpg + +import races +import careers +import character +import combat + diff --git a/tests/test_prog/test_prog.nit b/tests/test_prog/test_prog.nit new file mode 100644 index 0000000..d24c62f --- /dev/null +++ b/tests/test_prog/test_prog.nit @@ -0,0 +1,27 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A test program with a fake model to check model tools. +module test_prog + +import rpg +import game + +class Starter + fun start do end +end + +var starter = new Starter +starter.start + -- 1.7.9.5