mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/maintenance/autotest/obj_test/calc_test/fractions_products_test.py
00001 # -*- coding: utf-8 -*-
00002 
00003 # Mathmaker creates automatically maths exercises sheets
00004 # with their answers
00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net>
00006 
00007 # This file is part of Mathmaker.
00008 
00009 # Mathmaker is free software; you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation; either version 3 of the License, or
00012 # any later version.
00013 
00014 # Mathmaker is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 
00019 # You should have received a copy of the GNU General Public License
00020 # along with Mathmaker; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 import os
00024 import sys
00025 
00026 from core import *
00027 from core.base_calculus import *
00028 
00029 from maintenance.autotest import common
00030 
00031 check = common.check
00032 
00033 
00034 def action():
00035     if common.verbose:
00036         os.write(common.output, bytes("--- FRACTIONS PRODUCTS\n", 'utf-8'))
00037 
00038     product_fraction_5_4_times_5_5 = Product([Fraction((5, 4)),
00039                                               Fraction((5, 5))])
00040 
00041     product_fraction_9_minus2_times_minus8_10 = Product([Fraction((9, -2)),
00042                                                          Fraction((-8, 10))])
00043 
00044 
00045     #\frac{14}{7}\times \frac{12}{12}
00046     product_fraction_14_7_times_fraction_12_12 = Product([Fraction((14, 7)),
00047                                                          Fraction((12, 12))])
00048 
00049     check(product_fraction_5_4_times_5_5,
00050          ["\\frac{5}{4}\\times \\frac{5}{5}"])
00051 
00052     step_1 = product_fraction_5_4_times_5_5.calculate_next_step()
00053     check(step_1,
00054          ["\\frac{5\\times 5}{4\\times 5}"])
00055 
00056     step_2 = step_1.calculate_next_step()
00057     check(step_2,
00058          ["\\frac{\\bcancel{5}\\times 5}{4\\times \\bcancel{5}}"])
00059     step_3 = step_2.calculate_next_step()
00060     check(step_3,
00061          ["\\frac{5}{4}"])
00062     step_4 = step_3.calculate_next_step()
00063     check(step_4,
00064          ["None"])
00065 
00066     check(product_fraction_14_7_times_fraction_12_12,
00067          ["\\frac{14}{7}\\times \\frac{12}{12}"])
00068 
00069     step_1 = product_fraction_14_7_times_fraction_12_12.calculate_next_step()
00070     check(step_1,
00071          ["\\frac{14\\times 12}{7\\times 12}"])
00072 
00073     step_2 = step_1.calculate_next_step()
00074     check(step_2,
00075          ["\\frac{\\bcancel{7}\\times 2\\times \\bcancel{12}}" \
00076           + "{\\bcancel{7}\\times \\bcancel{12}}"])
00077     step_3 = step_2.calculate_next_step()
00078     check(step_3,
00079          ["2"])
00080     #     ["\\frac{2}{1}"])
00081     step_4 = step_3.calculate_next_step()
00082     check(step_4,
00083          ["None"])
00084     #step_5 = step_4.calculate_next_step()
00085     #check(step_5,
00086     #     ["None"])
00087 
00088 
00089 
00090     check(product_fraction_9_minus2_times_minus8_10,
00091          ["\\frac{9}{-2}\\times \\frac{-8}{10}"])
00092 
00093     step_1 = product_fraction_9_minus2_times_minus8_10.calculate_next_step()
00094     check(step_1,
00095          ["\\frac{9\\times 8}{2\\times 10}"])
00096 
00097     step_2 = step_1.calculate_next_step()
00098     check(step_2,
00099          ["\\frac{9\\times \\bcancel{2}\\times 4}{\\bcancel{2}\\times 10}"])
00100     step_3 = step_2.calculate_next_step()
00101     check(step_3,
00102          ["\\frac{9\\times \\bcancel{2}\\times 2}{\\bcancel{2}\\times 5}"])
00103     step_4 = step_3.calculate_next_step()
00104     check(step_4,
00105          ["\\frac{18}{5}"])
00106 
00107