def test_multi_die_multi_face(self): random.seed(0) # 1, 1, 0, 1, 2, 1, ... die1 = Die(["1", "2", "3"], "test_theme") die2 = Die(["4", "5", "6"], "test_theme") dice_set = DiceSet([die1, die2], "test_theme") self.assertEqual(_throw_to_faces(dice_set.throw()), ["2", "5"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["1", "5"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["3", "5"])
def test_single_die_multi_face(self): random.seed(0) # 1, 1, 0, 1, 2, ... die = Die(["1", "2", "3"], "test_theme") dice_set = DiceSet([die], "test_theme") self.assertEqual(_throw_to_faces(dice_set.throw()), ["2"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["2"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["1"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["2"]) self.assertEqual(_throw_to_faces(dice_set.throw()), ["3"])
def write_story(story_id): story = Story.query.filter_by(id=story_id).filter_by(published=0).first() if story is None: abort(404) if current_user.id != story.author_id: abort(401) rolls_outcome = json.loads(story.rolls_outcome) faces = _throw_to_faces(rolls_outcome) if request.method == 'POST': story.text = request.form["text"] story.title = request.form["title"] story.published = 1 if request.form["store_story"] == "1" else 0 if story.published == 1 and (story.title == "" or story.title == "None"): db.session.rollback() message = "You must complete the title in order to publish the story" return render_template("/write_story.html", theme=story.theme, outcome=rolls_outcome, title=story.title, text=story.text, message=message) if story.published and not is_story_valid(story.text, faces): db.session.rollback() message = "You must use all the words of the outcome!" return render_template("/write_story.html", theme=story.theme, outcome=rolls_outcome, title=story.title, text=story.text, message=message) if story.published == 0 and (story.title == "None" or len( story.title.replace(" ", "")) == 0): story.title = "Draft(" + str(story.theme) + ")" db.session.commit() if story.published == 1: return redirect("../story/" + str(story.id), code=302) elif story.published == 0: return redirect("../", code=302) return render_template("/write_story.html", theme=story.theme, outcome=rolls_outcome, title=story.title, text=story.text, message="")
def test_single_die_single_face(self): die = Die(["1"], "test_theme") dice_set = DiceSet([die], "test_theme") self.assertEqual(_throw_to_faces(dice_set.throw()), ["1"])
def test_multi_die_single_face(self): die1 = Die(["1"], "test_theme") die2 = Die(["2"], "test_theme") dice_set = DiceSet([die1, die2], "test_theme") self.assertEqual(_throw_to_faces(dice_set.throw()), ["1", "2"])