mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/maintenance/autotest/obj_test/calc_test/product_reduction_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("--- PRODUCTS' REDUCTION\n", 'utf-8'))
00037 
00038     temp_sum = Sum(['x', 3])
00039     temp_sum.set_exponent(3)
00040     temp_product = Product(Monomial((1, 2)))
00041     temp_product.set_exponent(3)
00042     temp_product_bis = Product([2, 3])
00043     temp_product_bis.set_exponent(3)
00044 
00045     big_product = Product([Monomial((2, 1)),
00046                            Monomial((-4, 2)),
00047                            temp_sum,
00048                            Item(5),
00049                            temp_product,
00050                            Item(('+', -1, 2)),
00051                            temp_product_bis])
00052 
00053 
00054     check(big_product,
00055          ["2x\\times (-4x^{2})(x+3)^{3}\\times 5\\times (x^{2})^{3}\\" \
00056           + "times (-1)^{2}\\times (2\\times 3)^{3}"])
00057 
00058     temp_product = big_product.order()
00059     check(temp_product,
00060          ["2\\times (-4)\\times 5\\times (-1)^{2}\\times 2^{3}\\times 3^{3}x" \
00061           + "\\times x^{2}x^{6}(x+3)^{3}"])
00062 
00063     big_product = big_product.reduce_()
00064 
00065     check(big_product,
00066          ["-8640x^{9}(x+3)^{3}"])
00067 
00068 
00069 
00070 
00071 
00072 
00073