Exemple #1
0
def test_curvefitting_general_fitting():
    """Tests the general_fitting() method of CurveFitting class"""

    # Let's define the three functions to be used for fitting
    def sin1(x):
        return sin(radians(x))

    def sin2(x):
        return sin(radians(2.0 * x))

    def sin3(x):
        return sin(radians(3.0 * x))

    a, b, c = cf4.general_fitting(sin1, sin2, sin3)
    assert abs(round(a, 2) - 1.2) < TOL, \
        "ERROR: In 1st general_fitting() test, 'a' value doesn't match"

    assert abs(round(b, 2) - (-0.77)) < TOL, \
        "ERROR: In 2nd general_fitting() test, 'b' value doesn't match"

    assert abs(round(c, 2) - 0.39) < TOL, \
        "ERROR: In 3rd general_fitting() test, 'c' value doesn't match"

    cf5 = CurveFitting([0, 1.2, 1.4, 1.7, 2.1, 2.2])

    a, b, c = cf5.general_fitting(sqrt)
    assert abs(round(a, 3) - 1.016) < TOL, \
        "ERROR: In 4th general_fitting() test, 'a' value doesn't match"

    assert abs(round(b, 3) - 0.0) < TOL, \
        "ERROR: In 5th general_fitting() test, 'b' value doesn't match"

    assert abs(round(c, 3) - 0.0) < TOL, \
        "ERROR: In 6th general_fitting() test, 'c' value doesn't match"
Exemple #2
0
def test_curvefitting_constructor():
    """Tests the constructor of CurveFitting class"""

    i = CurveFitting([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8])
    assert i._x == [5, 3, 6, 1, 2, 4], \
        "ERROR: 1st constructor test, 'x' values don't match"

    assert i._y == [10, 6, 12, 2, 4, 8], \
        "ERROR: 2nd constructor test, 'y' values don't match"

    j = CurveFitting([3, -8, 1, 12, 2, 5, 8])
    assert j._x == [0, 1, 2, 3, 4, 5, 6], \
        "ERROR: 3rd constructor test, 'x' values don't match"

    assert j._y == [3, -8, 1, 12, 2, 5, 8], \
        "ERROR: 4th constructor test, 'y' values don't match"

    k = CurveFitting(3, -8, 1, 12, 2, 5, 8)
    assert k._x == [3, 1, 2], \
        "ERROR: 5th constructor test, 'x' values don't match"

    assert k._y == [-8, 12, 5], \
        "ERROR: 6th constructor test, 'y' values don't match"
Exemple #3
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

from math import sqrt, radians, sin

from pymeeus.base import TOL
from pymeeus.CurveFitting import CurveFitting

# Declare some objects to be used later
cf1 = CurveFitting()
cf2 = CurveFitting()
cf3 = CurveFitting()
cf4 = CurveFitting()


def setup():
    """This function is used to set up the environment for the tests"""

    # Set up a few CurveFitting objects
    cf1.set([
        73.0, 38.0, 35.0, 42.0, 78.0, 68.0, 74.0, 42.0, 52.0, 54.0, 39.0, 61.0,
        42.0, 49.0, 50.0, 62.0, 44.0, 39.0, 43.0, 54.0, 44.0, 37.0
    ], [
        90.4, 125.3, 161.8, 143.4, 52.5, 50.8, 71.5, 152.8, 131.3, 98.5, 144.8,
        78.1, 89.5, 63.9, 112.1, 82.0, 119.8, 161.2, 208.4, 111.6, 167.1, 162.1