From cb3c5623aeaa65c2a39893f2e5e0ac993d8a3cc3 Mon Sep 17 00:00:00 2001 From: Freezed Date: Thu, 16 Jul 2020 08:41:01 +0200 Subject: [PATCH] Add specs for `sand_grain_drop.py` --- technical_tests/sand_grain_drop.py | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 technical_tests/sand_grain_drop.py diff --git a/technical_tests/sand_grain_drop.py b/technical_tests/sand_grain_drop.py new file mode 100644 index 0000000..a7e2c16 --- /dev/null +++ b/technical_tests/sand_grain_drop.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# coding: utf8 + +""" +Author: freezed 2020-07-16 +Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/ + +This file is part of [`free_zed/mypsb`](https://gitlab.com/free_zed/mypsb/) +""" + + +def main(pile, n): + """ + This function returns the situation of a sand `pile` after droping `n` + sand grain on top of it. + + + 1. Sand pile is a square table of uneven size (viewed from up) + 1. Sand grain is always dropped on center of pile. + 1. When a cell had 4 grains inside, these grains moves on the near 4th cells + 1. Grains going out the pile are losts + + :Tests: + >>> main([[1,1,1],[1,1,1],[1,1,1]],1) + [[1, 1, 1], [1, 2, 1], [1, 1, 1]] + >>> main([[1,1,1],[1,1,1],[1,1,1]],2) + [[1, 1, 1], [1, 3, 1], [1, 1, 1]] + >>> main([[1,1,1],[1,1,1],[1,1,1]],3) + [[1, 2, 1], [2, 0, 2], [1, 2, 1]] + >>> main([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]],1) + [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]] + >>> main([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]],3) + [[1, 1, 1, 1, 1], [1, 1, 2, 1, 1], [1, 2, 0, 2, 1], [1, 1, 2, 1, 1], [1, 1, 1, 1, 1]] + >>> main([[0,0,3,0,0],[0,0,3,0,0],[3,3,3,3,3],[0,0,3,0,0],[0,0,3,0,0]],1) + [[0, 1, 0, 1, 0], [1, 2, 2, 2, 1], [0, 2, 0, 2, 0], [1, 2, 2, 2, 1], [0, 1, 0, 1, 0]] + """ + + return pile + + +if __name__ == "__main__": + import doctest + + doctest.testmod()