Пример #1
0
    def test_add_1(self):
        num1 = 10
        num2 = '20'
        result = utility.add(num1, num2)

        # тэнцүү эсэхийг шалгах
        self.assertEqual(result, 30)
Пример #2
0
    def test_add_2(self):
        num1 = None
        num2 = 10
        result = utility.add(num1, num2)

        # илэрхийлэл True утгатай эсэхийг шалгах
        self.assertTrue(isinstance(result, TypeError))
 def search( self, start, end, minDist ):
     """@param start: a point in C-space
      @param end: the end point in C-Space
      @param minDist: the min dist for binary search to consider a point precise enough"""
     startAngles = self.mCSpace.map2UnscaledSpace( start );
     endAngles = self.mCSpace.map2UnscaledSpace( end )
     startCollide = self.mClsnMgr.ifCollide( startAngles );
     endCollide = self.mClsnMgr.ifCollide(endAngles);
     if ( startCollide == endCollide ):
         return None;
     
     while( startCollide != endCollide ):
         if( utility.euclideanDist( start, end ) <= minDist ):
             if( startCollide == False ):
                 return start;
             else:
                 return end;
         sum = utility.add( start, end );
         mid = utility.devide( sum, 2 );
         midAngles = self.mCSpace.map2UnscaledSpace( mid )
         midCollide = self.mClsnMgr.ifCollide( midAngles );
         if( midCollide == startCollide ):
             start = mid;
             startCollide = midCollide;
         else:
             end = mid;
             endCollide = midCollide;
 def __findFarestPoint__( self, outPoint ):
     """from direction center-->outPoint, this method finds a point that is farest from
      the center of the grid, yet still inside the grid."""
     end = outPoint;
     endInside = self.inside( end );
     if endInside: return outPoint;
     start = self.mCenter;
     startInside = self.inside( start );
     
     while( True ):
         if ( utility.euclideanDistSqr( start, end ) <= 4 ):
             return start;
         mid = utility.devide( utility.add( start, end ), 2);
         if self.inside( mid ):
             start = mid;
         else:
             end = mid;
Пример #5
0
import utility
from utility import divide

print(utility.add(10, 5))
print(divide(50, 5))
Пример #6
0
import utility as ul

if __name__ == "__main__":
    print(ul.add(100, 200))
Пример #7
0
def test_add():
    result = add(10, 10)
    assert result == 20
Пример #8
0
def test_add2(val1, val2, result):
    res = add("python", 'java')
    assert res == result
Пример #9
0
print(calendar.calendar(2019))
'''
'''
import calendar as c
print(c.month(2019,1))
'''
'''
from calendar import month
print(month(1700,2))
'''
'''
import utility as u
u.add(8,7,4,51)
'''
import utility as u
x = u.add(46, 34, 7, 4, 68)
print(x)

#pip install module_name
#pip uninstall module_name
'''
lambda

lambda operator or lambda function is used for creating 
small, one-time and anonymous function objects in Python.
Syntax:-
	lambda arguments : expression

add = lambda x,y : x + y 
b=add(5,4)
print(b)
Пример #10
0
def test_add3():
    results = add(10, 'python')
    assert results == 'invalid input'  #here we write same things which is in the escept parrt of he utility file.
Пример #11
0
def callback(data):
    # for each rule try to do something
    for metric in config['metrics']:
        name = metric['name']
        labelsDict = {
        }  # needed to update metrics, collect as labels are updated

        if 'labels' in metric and metric['labels'] is not None:
            for key in metric['labels'].keys():
                label = metric['labels'][key]
                if 'regex' in label:
                    m = re.match(label['regex'], data)
                    if m is not None and m.groups() is not None and len(
                            m.groups()) > 0 and m.groups()[0] is not None:
                        label['value'] = m.groups()[0].strip()
                if labelsDict is not None and 'value' in label:
                    labelsDict[key] = label['value']
                else:
                    # didn't have a value for a label, wipe the label dict (meaning we will not save a metric yet)
                    labelsDict = None

        # see if we can match any of the metric rules
        if 'rules' in metric:
            for rule in metric['rules']:
                value = None
                if 'value' in rule:
                    value = rule['value']
                matched = False
                if 'regex' in rule:
                    m = re.match(rule['regex'], data)
                    if m is not None:
                        # update value only if it's not set in config (hard coded)
                        matched = True
                        if value is None and m.groups() is not None and len(
                                m.groups()) > 0 and m.groups()[0] is not None:
                            value = m.groups()[0].strip()

                # load cached value if we didn't find a match
                cached_value = None
                if 'cached_value' in rule:
                    cached_value = rule['cached_value']

                # if we do have a value but don't have all labels cache the value and bail
                if value is not None and labelsDict is None:
                    rule['cached_value'] = value
                    continue

                # and finally, only proceed if we have all label values and matched or have a cache
                if labelsDict is not None and (matched
                                               or cached_value is not None):
                    # we have somtehing to do! yay.
                    op = rule['op']
                    if labelsDict is None:
                        rule['cached_value'] = value
                    else:
                        #print("{}({}, {}, {})".format(op,name,value,labelsDict))
                        if op == 'add':
                            # gauge
                            utility.add(name, float(value), labelsDict)
                        if op == 'set':
                            # gauge
                            utility.set(name, float(value), labelsDict)
                        if op == 'inc':
                            # counter
                            utility.inc(name, labelsDict)
                        if op == 'dec':
                            # counter
                            utility.dec(name, labelsDict)

                        # wipe cached value if we have one
                        if 'cached_value' in rule:
                            rule['cached_value'] = None