Example #1
0
def test_empty_texts():
    assert str(Elem(content=Text(''))) == '<div></div>'
    assert str(Elem(content=[Text(''), Text('')])) == '<div></div>'
    assert str(
        Elem(content=[Text('foo'), Text(''), Elem()])) == '<div>\n  foo\
\n  <div></div>\n</div>'

    print('Elem with empty texts : OK.')
Example #2
0
def test_embedding():
    assert (str(Elem(content=Elem(content=Elem(content=Elem())))) == """<div>
  <div>
    <div>
      <div></div>
    </div>
  </div>
</div>""")
    print('Element embedding : OK.')
Example #3
0
def test_errors():
    # Type error if the content isn't made of Text or Elem.
    try:
        Elem(content=1)
    except Exception as e:
        assert type(e) == Elem.ValidationError
    # The right way :
    assert str(Elem(content=Text(1))) == '<div>\n  1\n</div>'

    # Type error if the elements of the list aren't Text or Elem instances.
    try:
        Elem(content=['foo', Elem(), 1])
    except Exception as e:
        assert type(e) == Elem.ValidationError
    # The right way :
    assert (str(
        Elem(content=[Text('foo'), Elem(), Text(1)])) ==
            '<div>\n  foo\n  <div></div>\n  1\n</div>')

    # Same with add_method()
    try:
        elem = Elem()
        elem.add_content(1)
        raise (Exception("incorrect behaviour."))
    except Exception as e:
        assert isinstance(e, Elem.ValidationError)

    # Or with lists :
    try:
        elem = Elem()
        elem.add_content([
            1,
        ])
        raise (Exception('incorrect behaviour'))
    except Exception as e:
        assert isinstance(e, Elem.ValidationError)

    # str can't be used :
    try:
        elem = Elem()
        elem.add_content([
            '',
        ])
        raise (Exception("incorrect behaviour."))
    except Exception as e:
        assert isinstance(e, Elem.ValidationError)

    try:
        elem = Elem(content='')
        raise (Exception("incorrect behaviour."))
    except Exception as e:
        assert isinstance(e, Elem.ValidationError)
    print('Error cases : OK.')
Example #4
0
def last_test():
    assert (str(
        Elem(tag='html',
             content=[
                 Elem(tag='head',
                      content=Elem(tag='title',
                                   content=Text('"Hello ground!"'))),
                 Elem(tag='body',
                      content=[
                          Elem(tag='h1', content=Text('"Oh no, not again!"')),
                          Elem(tag='img',
                               attr={'src': "http://i.imgur.com/pfp3T.jpg"},
                               tag_type='simple')
                      ])
             ])) == """<html>
  <head>
    <title>
      "Hello ground!"
    </title>
  </head>
  <body>
    <h1>
      "Oh no, not again!"
    </h1>
    <img src="http://i.imgur.com/pfp3T.jpg" />
  </body>
</html>""")
    print('Last Test : OK.')
def last_test():
    print(
        str(
            Elem(tag='html',
                 content=[
                     Elem(tag='head',
                          content=Elem(tag='title',
                                       content=Text('"Hello ground!"'))),
                     Elem(tag='body',
                          content=[
                              Elem(tag='h1',
                                   content=Text('"Oh no, not again!"')),
                              Elem(
                                  tag='img',
                                  attr={'src': "http://i.imgur.com/pfp3T.jpg"},
                                  tag_type='simple')
                          ])
                 ])))
    # == '''<html>
    #   <head>
    #     <title>
    #       "Hello ground!"
    #     </title>
    #   </head>
    #   <body>
    #     <h1>
    #       "Oh no, not again!"
    #     </h1>
    #     <img src="http://i.imgur.com/pfp3T.jpg"/>
    #   </body>
    # </html>'''
    #    )
    print('Last Test : OK.')
Example #6
0
def test_elem_basics():
    # Default behaviour :
    assert str(Elem()) == '<div></div>'
    # Arguments order :
    assert str(Elem('div', {}, None, 'double')) == '<div></div>'
    # Argument names :
    assert str(Elem(tag='body', attr={}, content=Elem(),
                    tag_type='double')) == '<body>\n  <div></div>\n</body>'
    # With elem as content :
    assert str(Elem(content=Elem())) == '<div>\n  <div></div>\n</div>'
    # With list as content :
    assert str(Elem(content=[Text('foo'), Text('bar'), Elem()])) == '<div>\n  foo\n  bar\n \
 <div></div>\n</div>'
    print('Basic Elem behaviour : OK.')
Example #7
0
 def __init__(self, mat_cls, mesh_cls, prob_dict):
     # equation name
     self._name = 'nda'
     # mesh data
     self._mesh = mesh_cls
     self._cell_length = mesh_cls.cell_length()
     # quantities of interest
     self._keff = 1.0
     self._keff_prev = 1.0
     # preassembly-interpolation data
     self._elem = Elem(self._cell_length)
     # material ids and group info
     self._mids = mat_cls.get('ids')
     self._n_grp = mat_cls.get('n_grps')
     self._g_thr = mat_cls.get('g_thermal')
     # mesh
     self._mesh = msh_cls
     # problem type
     self._is_eigen = prob_dict['is_eigen_problem']
     self._do_ua = prob_dict['do_ua']
     # linear algebra objects
     self._sys_mats = {}
     self._sys_rhses = {
         k: np.ones(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._fixed_rhses = {
         k: np.zeros(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._sflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_grp)}
     # linear solver objects
     self._lu = {}
     # total number of components: keep consistency with HO
     self._n_tot = self._n_grp
     # all material
     self._dcoefs = mat_cls.get('diff_coef')
     self._sigts = mat_cls.get('sig_t')
     self._sigses = mat_cls.get('sig_s')
     self._sigrs = mat_cls.get('sig_r')
     self._fiss_xsecs = mat_cls.get('chi_nu_sig_f')
     # derived material properties
     self._sigrs_ua = mat_cls.get('sig_r_ua')
     self._dcoefs_ua = mat_cls.get('diff_coef_ua')
     # fission source
     self._global_fiss_src = self._calculate_fiss_src()
     self._global_fiss_src_prev = self._global_fiss_src
     # assistance object
     self._local_dof_pairs = pd(xrange(4), xrange(4))
    def __init__(self, n: int, view: 'View'):
        self.view = view
        sorted_array = []
        for i in range(1, n + 1):
            sorted_array.append(i)

        self.array = []

        for i in range(0, n):
            rand_elem = random.choice(sorted_array)
            sorted_array.remove(rand_elem)
            self.array.append(Elem(rand_elem, self))

        self.high_lighted1 = -1
        self.high_lighted2 = -1
        self.comparisons = 0
        self.mutations = 0
Example #9
0
 def __init__(self, mat_cls, mesh_cls, prob_dict):
     # name of the Equation
     self._name = 'saaf'
     # mesh data
     self._mesh = mesh_cls
     self._cell_length = mesh_cls.cell_length()
     # quantities of interest
     self._keff = 1.0
     self._keff_prev = 1.0
     # preassembly-interpolation data
     self._elem = Elem(self._cell_length)
     # material data
     self._n_grp = mat_cls.get('n_grps')
     self._g_thr = mat_cls.get('g_thermal')
     self._sigts = mat_cls.get('sig_t')
     self._isigts = mat_cls.get('inv_sig_t')
     self._fiss_xsecs = mat_cls.get_per_str('chi_nu_sig_f')
     self._nu_sigfs = mat_cls.get('nu_sig_f')
     self._sigses = mat_cls.get_per_str('sig_s')
     self._dcoefs = mat_cls.get('diff_coef')
     self._mids = mat_cls.ids()
     # derived material data
     self._ksi_ua = mat_cls.get('ksi_ua')
     # problem type: is problem eigenvalue problem
     # aq data in forms of dictionary
     self._aq = AQ(prob_dict['sn_order']).get_aq_data()
     self._n_dir = self._aq['n_dir']
     # total number of components in HO
     self._n_tot = self._n_grp * self._n_dir
     # get a component indexing mapping
     self._comp = dict()
     # component to group map
     self._comp_grp = dict()
     # component to direction map
     self._comp_dir = dict()
     self._generate_component_map()
     # local vectors
     self._rhs_mats = dict()
     self._preassembly_rhs()
     # related to global matrices and vectors
     self._n_dof = mesh_cls.n_node()
     self._sys_mats = {}
     # be very careful about the following
     self._sys_rhses = {
         k: np.ones(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._fixed_rhses = {
         k: np.zeros(self._n_dof)
         for k in xrange(self._n_tot)
     }
     self._aflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_tot)}
     # scalar flux for current calculation
     self._sflxes = {k: np.ones(self._n_dof) for k in xrange(self._n_grp)}
     # linear solver objects
     self._lu = {}
     # source iteration tol
     self._tol = 1.0e-7
     # fission source
     self._global_fiss_src = self._calculate_fiss_src()
     self._global_fiss_src_prev = self._global_fiss_src
     # assistance:
     self._local_dof_pairs = pd(xrange(4), xrange(4))