Пример #1
0
def test_Laminate_eq1():
    '''Compare 5-ply to self should be True; testing == of LaminateModels'''
    case1 = ut.laminator('400-[200]-800')
    case2 = ut.laminator('400-200-800')
    standard = [LM for case_ in case1.values() for LM in case_.LMs]
    unconventional = [LM for case_ in case2.values() for LM in case_.LMs]
    # Internal converts unconventional string to be equivalent to standard.
    actual = (standard[0] == unconventional[0])
    nt.assert_true(actual)
Пример #2
0
def test_Laminate_ne1():
    '''Compare 5-ply to even plies should be False; testing != of LaminateModels'''
    case1 = ut.laminator(dft.geos_standard)
    cases1 = ut.laminator(dft.geos_even)
    standard = [LM for case_ in case1.values() for LM in case_.LMs]
    for case in cases1.values():
        for even_LM in case.LMs:
            actual = (even_LM != standard[0])
            print(even_LM)
            print(standard[0])
            print(actual)
            nt.assert_true(actual)
Пример #3
0
def test_Laminate_attr_extrema():
    case1 = ut.laminator(dft.geos_full, ps=[5])
    case2 = ut.laminator(dft.geos_full, ps=[2])

    for case_full, case_trimmed in zip(case1.values(), case2.values()):
        for LM_full, LM_trimmed in zip(case_full.LMs, case_trimmed.LMs):
            actual = LM_full.extrema
            actual.reset_index(drop=True, inplace=True)
            expected = LM_trimmed.LMFrame
            #print(actual)
            #print(expected)
            ut.assertFrameEqual(actual, expected)    
Пример #4
0
def test_theories_FeatureInput_globals1():
    '''Check globals are correct in updated FeatureInput for 400-[200]-800 post-theories.'''
    case = ut.laminator(geos=dft.geos_standard)
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.FeatureInput                       # updated FeatureInput
            expected = {'Geometry': LM.Geometry,
                        'Parameters': {'P_a': 1, 'R': 0.012, 'a': 0.0075,
                                       'p': 5, 'r': 2e-4},
                        'Properties': LM.mat_props,
                        'Materials': LM.materials,               
                        'Model': 'Wilson_LT',
                        'Globals': {'D_11T': 31.664191802890315,
                                     'D_12T': 7.9406108505093584,
                                     'D_11p': 0.033700807714524279,
                                     'D_12n': -0.0084513446948124519,
                                     'M_r': 0.15666895161350616,
                                     'M_t': 0.216290324549788,
                                     'K_r': 0.0034519261262397653,
                                     'K_t:': 0.0059650953251038216,
                                     'v_eq ': 0.25077573114575868},
                        }
            #print(actual)
            #print(expected)
            #assert actual == expected
            '''Refactor dict comparison'''
            ##del actual['Materials']
            ##del expected['Materials']
            nt.assert_equal(actual, expected)
Пример #5
0
def test_distribplot_instance1():
    '''Check distribplot returns an axes.'''
    case = ut.laminator(['400-200-800'])[0]
    plot = la.output_._distribplot(case.LMs, normalized=True, extrema=True)

    nt.assert_is_instance(plot, mpl.axes.Axes)

    plt.close()
Пример #6
0
def test_distribplot_input_error2():
    '''Check still looks for stress column, even if bad x column name given.'''
    x_col = 'bad_column_name'
    case = ut.laminator(['400-200-800'])[0]
    plot = la.output_._distribplot(case.LMs, x=x_col)
    nt.assert_is_instance(plot, mpl.axes.Axes)

    plt.close()
Пример #7
0
def test_getmultigeo1():
    '''Check strings are extracted from a "multi" laminate Frame, nplies >= 5.'''
    case = ut.laminator(['400-200-800'])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = ut.get_multi_geometry(LM.LMFrame)
            #expected = '400-[200]-800'                       # pre to_gen_convention()
            expected = '400.0-[200.0]-800.0'
            nt.assert_equal(actual, expected)
Пример #8
0
def test_getspecialgeo1():
    '''Check strings are extracted from a special laminate Frame, nplies <= 4.'''
    case = ut.laminator(['400-200-0'])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = ut.get_special_geometry(LM.LMFrame)
            ##expected = '400-[200]-0'                       # pre to_gen_convention()
            expected = '400.0-[200.0]-0.0'
            nt.assert_equal(actual, expected)
Пример #9
0
def test_distribplot_annotate1():
    '''Check iif text exists on the plot when annotate=True.'''
    case = ut.laminator(['400-200-800'])[0]
    plot = la.output_._distribplot(case.LMs, annotate=True)

    actual = upt.has_annotations(plot.texts)
    nt.assert_true(actual)

    plt.close()
Пример #10
0
def test_laminator_type3():
    '''Check defaults triggerd if nothing is passed in.'''
    case1 = ut.laminator()
    LM = case1[0]
    actual = LM.frames[0]
    case2 = la.distributions.Case(dft.load_params, dft.mat_props)
    case2.apply(['400-200-800'])
    expected = case2.frames[0]
    ut.assertFrameEqual(actual, expected)
Пример #11
0
def test_distribplot_annotate2():
    '''Check ift text exists; return False when annotate=False'''
    case = ut.laminator(['400-200-800'])[0]
    plot = la.output_._distribplot(case.LMs, annotate=False)

    actual = upt.has_annotations(plot.texts)
    nt.assert_false(actual)

    plt.close()
Пример #12
0
def test_laminator_gencon1():
    '''Check returns a geometry string in General Convention; converts 'S'.'''
    case = ut.laminator(['400-0-400S'])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = ut.get_special_geometry(LM.LMFrame)
            ##expected = '400-[0]-800'                       # pre to_gen_convention()
            expected = '400.0-[0.0]-800.0'
            nt.assert_equal(actual, expected)
Пример #13
0
def test_models_WisonLT_diameter1():
    '''Check the support radius, a, is smaller than the sample radius, R.'''
    case = ut.laminator(geos=dft.geos_standard)
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.FeatureInput['Parameters']['a']
    expected = LM.FeatureInput['Parameters']['R']
    #assert actual < expected
    nt.assert_less(actual, expected)
Пример #14
0
def test_theories_FeatureInput_globels2():
    '''Globals stay None if p=1, post LMFrame processing.'''
    # TODO: Opportunity to use a select method for p spefically.
    case = ut.laminator(geos=dft.geos_standard, ps=[1])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.FeatureInput['Globals']
            expected = None
            #print(LM.FeatureInput)
            nt.assert_equal(actual, expected)
Пример #15
0
def test_extract_equivalence4():
    '''Given a case, line plot data agrees with the DataFrame data; {extrema,normalized}=False.'''

    case = ut.laminator(['400-[200]-800'])                 # unnormalized multiplot requires only one geoemetry
    line_df_case = upt.extract_plot_LM_xy(case, extrema=False, normalized=False)
    line_data, df_data = line_df_case

    actual = line_data
    expected = df_data
    nt.assert_equal(actual, expected)
Пример #16
0
def test_extract_equivalence2():
    '''Given a case, line plot data agrees with the DataFrame data; extrema=True.'''

    case = ut.laminator(['400-[200]-800', '400-[400]-400'])
    line_df_case = upt.extract_plot_LM_xy(case, extrema=True)
    line_data, df_data = line_df_case

    actual = line_data
    expected = df_data
    nt.assert_equal(actual, expected)
Пример #17
0
def test_Laminate_compare_sets1():
    '''Check __eq__, __ne__ and sets containing Laminate object instances.'''
    # Tests __hash__
    cases1 = ut.laminator(dft.geo_inputs['5-ply'])
    cases2 = ut.laminator(dft.geo_inputs['1-ply'])
    LM1 = cases1[0].LMs[0]                                     # 400-200-800
    LM2 = cases1[0].LMs[1]                                     # 400-[200]-800            
    LM3 = cases1[0].LMs[2]                                     # 400-[200]-400S
    LM4 = cases2[0].LMs[0]                                     # 0-0-2000 
    
    #assert set([LM1]) == set([LM1])
    #assert set([LM1]) == set([LM2])
    #assert set([LM1]) != set([LM3])
    #assert set([LM1]) != set([LM4])
    
    nt.assert_set_equal(set([LM1, LM2]), set([LM1, LM2]))
    nt.assert_set_equal(set([LM1]), set([LM2]))
    nt.assert_set_equal(set([LM2]), set([LM1]))
    nt.assert_true(set([LM1]) != set([LM3]))
    nt.assert_true(set([LM1]) != set([LM4]))
    nt.assert_equal(len(set([LM1,LM2,LM3,LM4])), 3)            
Пример #18
0
def test_models_WisonLT_r1():
    '''Check singularity in log of moment eqn when r = 0; ZeroDivisionError.'''
    zero_r = {'R' : 12e-3,                                 # specimen radius
              'a' : 7.5e-3,                                # support ring radius
              'p' : 5,                                     # points/layer
              'P_a' : 1,                                   # applied load 
              'r' : 0,          #                          # radial distance from center loading
              }
    case = ut.laminator(geos=dft.geos_standard, load_params=zero_r) 
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.LMFrame
Пример #19
0
def test_models_WisonLT_a2():
    '''Check the singularity in log of moment eqn when support radius, a < 0; ValueError.'''
    neg_a = {'R' : 12e-3,                                  # specimen radius
              'a' : -7.5e-3,       #                       # support ring radius
              'p' : 5,                                     # points/layer
              'P_a' : 1,                                   # applied load 
              'r' : 2e-4,                                  # radial distance from center loading
              }
    case = ut.laminator(geos=dft.geos_standard, load_params=neg_a) 
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.LMFrame
Пример #20
0
def test_laminator_consistency1():
    '''Check laminator yields same LMFrame as classic case building.'''
    case = ut.laminator(geos=dft.geos_all, ps=[5])
    for case_ in case.values():
        case1 = case_
    case2 = la.distributions.Case(load_params, mat_props)
    case2.apply(dft.geos_all)
    #print(case1)
    #print(case2)
    ##for actual, expected in zip(case1, case2.LMs):
    for actual, expected in zip(case1.LMs, case2.LMs):
        #print(actual)
        #print(expected)
        ut.assertFrameEqual(actual.LMFrame, expected.LMFrame)
Пример #21
0
def test_theories_FeatureInput_differ():
    '''Check last FeatureInput Geometry in a case differfrom random others.'''
    case = ut.laminator(dft.geos_full)
    LM = [LM for case_ in case.values() for LM in case_.LMs]
    actual1 = LM[4].FeatureInput['Geometry']
    actual2 = LM[2].FeatureInput['Geometry']
    expected1 = la.input_.Geometry('400-[200]-800')
    expected2 = la.input_.Geometry('600-[0]-800')
    last_item = LM[-1].FeatureInput['Geometry'] 
    
    nt.assert_equal(actual1, expected1)
    nt.assert_equal(actual2, expected2)
    nt.assert_not_equal(actual1, last_item)
    nt.assert_not_equal(actual2, last_item)
Пример #22
0
def test_theories_Exception_default1():
    '''Check LMFrame is set by LFrame if exception raised.'''
    # Force an exception in Wilson_LT; r must be non-zero
    zero_r = {'R' : 12e-3,                                 # specimen radius
              'a' : 7.5e-3,                                # support ring radius
              'p' : 5,                                     # points/layer
              'P_a' : 1,                                   # applied load 
              'r' : 0,          #                          # radial distance from center loading
              }
    case = ut.laminator(geos=dft.geos_standard, load_params=zero_r) 
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.LMFrame
            expected = LM.LFrame
            #print(actual)                                 # should get LFrame
            ut.assertFrameEqual(actual, expected) 
Пример #23
0
def test_theories_FeatureInput_consistency1():
    '''Check FeatureInput from classic case building is consistent with 
    utils tools automatic case building, post-theories.'''
    case1 = la.distributions.Case(dft.load_params, dft.mat_props) 
    case1.apply(dft.geos_standard)                         # classic case build
    case2 = ut.laminator(geos=dft.geos_standard)           # auto case build
    LM = case1.LMs[0]
    ##del LM.FeatureInput['Geometry']                        # comp. unsupported 0.4.3d
    ##del LM.FeatureInput['Materials']
    expected = LM.FeatureInput
    
    for case_ in case2.values():
        for LM in case_.LMs:
            ##del LM.FeatureInput['Geometry']
            ##del LM.FeatureInput['Materials']
            actual = LM.FeatureInput                       # updated FeatureInput
        #print(actual)
        #print(expected)
        nt.assert_equal(actual, expected)            
Пример #24
0
def test_models_WisonLT_a3():
    '''Raise exception if support radius, a, is larger than the sample radius, R.

    See Also
    --------
    - test_models_WisonLT_diameter1()

    '''
    big_a = {
        'R': 12e-3,                                        # specimen radius
        'a': 7.5,                                          # support ring radius
        'p': 5,                                            # points/layer
        'P_a': 1,                                          # applied load
        'r': 2e-4,                                         # radial distance from center loading
    }
    case = ut.laminator(geos=dft.geos_standard, load_params=big_a)
    for case_ in case.values():
        for LM in case_.LMs:
            actual = LM.FeatureInput['Parameters']['a']
    expected = LM.FeatureInput['Parameters']['R']
    #assert actual < expected
    nt.assert_less(actual, expected)
Пример #25
0
def test_theories_matl_order1():
    '''Check the material stack order is correct in LMFrame.'''
    # Amend geometry inputs even and dissimilar  
    dft.geos_full.append(dft.geos_even[0])
    case = ut.laminator(geos=dft.geos_full)
    expected_mix = [['HA'],
                    ['HA', 'PSu'],
                    ['HA', 'PSu', 'HA'],
                    ['HA', 'PSu', 'HA', 'PSu'],
                    ['HA', 'PSu', 'HA', 'PSu', 'HA'],
                    ['HA', 'PSu', 'HA', 'PSu', 'HA', 'PSu'],
                    ['HA', 'PSu', 'HA', 'PSu', 'HA', 'PSu', 'HA',],
                    ['HA', 'PSu', 'HA', 'PSu', 'HA', 'PSu', 'HA', 'PSu', 'HA'],
                    # even --------------------------------------
                    ['HA', 'PSu']                         # simple to preserve test                    
                   ]
    for case_ in case.values():
        for LM, expected in zip(case_.LMs, expected_mix):
            grouped = LM.LMFrame.groupby('layer')['matl']
            actual = grouped.unique().tolist()
            #print(actual)
            #assert actual == expected
            nt.assert_equal(actual, expected)
Пример #26
0
# Commented nt.raise --> handled in Laminate._update_calculations().
# Although program will run, tracebacks will print if exceptions were raised.

import pandas as pd
import nose.tools as nt

import lamana as la
from lamana.input_ import BaseDefaults
#from lamana.lt_exceptions import IndeterminateError        # unused
from lamana.models import Wilson_LT as wlt
from lamana.utils import tools as ut

# Global Cases
bdft = BaseDefaults()
dft = wlt.Defaults()
case = ut.laminator(geos=dft.geos_standard)
cases = ut.laminator(geos=dft.geos_all, ps=[2, 3, 4, 5], verbose=True)

# TESTS -----------------------------------------------------------------------
# Tests that check the LMFrame rollsback to LFrame if exceptions are made.


# Models ----------------------------------------------------------------------
# NOTE: the test for errors are commented out because errors are caught
# in constructs and prevent breaking
@nt.raises(ZeroDivisionError)
def test_models_WisonLT_r1():
    '''Check singularity in log of moment eqn when r = 0; ZeroDivisionError.'''
    zero_r = {
        'R': 12e-3,                                        # specimen radius
        'a': 7.5e-3,                                       # support ring radius
Пример #27
0
def test_distribplot_unnormalized_error1():
    '''Check raises PlottingError if geometry > 1 for unnormalized plot.'''
    case = ut.laminator(['400-200-800', '400-400-400'])[0]
    plot = la.output_._distribplot(case.LMs, normalized=False)

    plt.close()
Пример #28
0
def test_lamainator_type1():
    '''Check raises Exception if geos is not a list.'''
    actual = ut.laminator(geos={'400-200-800'})
Пример #29
0
def test_getspecialgeo2():
    '''Check error is raised if not special, nplies > 4.'''
    case = ut.laminator(['400-200-800'])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = ut.get_special_geometry(LM.LMFrame)
Пример #30
0
def test_getmultigeo2():
    '''Check error is raised if not "multi", rather a special, nplies < 4.'''
    case = ut.laminator(['400-200-0'])
    for case_ in case.values():
        for LM in case_.LMs:
            actual = ut.get_multi_geometry(LM.LMFrame)