Пример #1
0
 def test_add(self):
     print('add')
     self.assertEqual(3, add(1, 2))
     self.assertNotEqual(3, add(2, 2))
Пример #2
0
from myfunc import add
from myfunc2 import add2

print(add(2, 2))
print(add2(2, 2))
Пример #3
0
 def test_add_nums(self):
   actual = add(1,10)
   assert actual == 11
Пример #4
0
def main():

    print("hello python")

    # function call
    var1 = add(2, 3)
    print("current file function call: " + str(var1))

    # cross file function call
    var2 = myfunc.add(1, 2)
    print("cross file function call: " + str(var2))

    # timestamp
    now = time.time()
    print("now in seconds: " + str(now))
    timearr = time.localtime(now)
    print("hour: {0}, minute: {1}, seconds: {2}".format(
        timearr.tm_hour, timearr.tm_min, timearr.tm_sec))

    # hardware, mac address
    mac = hex(getnode())
    print("mac: " + mac)

    # file1
    fout = open("abc.txt", "w", encoding="utf-8")
    fout.write("abcdefg\n")
    fout.close()

    # file2
    with open("def.txt", "w", encoding="utf-8") as fh:
        fh.write("abcdefghijk\n")

    # perfermence
    t1 = time.clock()
    ans = math.sqrt(2)
    t2 = time.clock()
    print("sqrt(2) = {0}, elapse time: {1}".format(ans, t2-t1))

    # object
    c = myobj.Circle()
    print("area = {0}".format(c.area))

    # thread - normal
    thread1 = MyThread(1, "thread-1", 1)
    thread2 = MyThread(2, "thread-2", 2)

    thread1.start()
    thread2.start()

    print("start join: {0}".format(time.time()))
    thread1.join()
    thread2.join()
    print("end join: {0}".format(time.time()))

    # thread - external file
    thread3 = mythread.ExternalFileThread(3, "thread-3")
    thread3.start()
    thread3.join()

    # thread - mutex lock
    for i in range(5):
        t = mythread.MutexDemoThread(i)
        t.start()
Пример #5
0
 def test_invalid_arg1(self):
   actual = add(None,1)
Пример #6
0
 def test_invalid_arg2(self):
   actual = add(1,None)
Пример #7
0
def test_add_Numbers():
  actual = add(-1,1)
  assert actual == 0
Пример #8
0
def test_addNumbers():
    print("add")
    actual = add(-1, 1)
    assert actual == 0
Пример #9
0

import myfunc


if __name__ == '__main__':
    print(__name__)
    print(myfunc.add(4,3))
Пример #10
0
def main():

    print("hello python")

    # function call
    var1 = add(2, 3)
    print("current file function call: " + str(var1))

    # cross file function call
    var2 = myfunc.add(1, 2)
    print("cross file function call: " + str(var2))

    # timestamp
    now = time.time()
    print("now in seconds: " + str(now))
    timearr = time.localtime(now)
    print("hour: {0}, minute: {1}, seconds: {2}".format(
        timearr.tm_hour, timearr.tm_min, timearr.tm_sec))

    # hardware, mac address
    mac = hex(getnode())
    print("mac: " + mac)

    # file1
    fout = open("abc.txt", "w", encoding="utf-8")
    fout.write("abcdefg\n")
    fout.close()

    # file2
    with open("def.txt", "w", encoding="utf-8") as fh:
        fh.write("abcdefghijk\n")

    # perfermence
    t1 = time.clock()
    ans = math.sqrt(2)
    t2 = time.clock()
    print("sqrt(2) = {0}, elapse time: {1}".format(ans, t2 - t1))

    # object
    c = myobj.Circle()
    print("area = {0}".format(c.area))

    # thread - normal
    thread1 = MyThread(1, "thread-1", 1)
    thread2 = MyThread(2, "thread-2", 2)

    thread1.start()
    thread2.start()

    print("start join: {0}".format(time.time()))
    thread1.join()
    thread2.join()
    print("end join: {0}".format(time.time()))

    # thread - external file
    thread3 = mythread.ExternalFileThread(3, "thread-3")
    thread3.start()
    thread3.join()

    # thread - mutex lock
    for i in range(5):
        t = mythread.MutexDemoThread(i)
        t.start()
Пример #11
0
 def test_addition(self):
     self.assertEqual(myfunc.add(5), 6)
Пример #12
0
def test_invalid_args2():
    # 入力値チェックで RuntimeError を投げることを機能仕様としたいが、
    # まだ未実装なので + 演算で TypeError が発生する
    print("test2")
    actual = add(1, None)
Пример #13
0
def test_invalid_arg1():
    print("test1")
    actual = add(None, 1)
Пример #14
0
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import myfunc

if __name__ == "__main__":

    result = myfunc.add(1, 2)
    print('result: {}'.format(result))

'''
handy@ubuntu:~/playground/tutorials/python/03_cross_file_function$ python3 main.py
result: 3
'''
 def test_add(self):
     print("测试add方法")
     self.assertEqual(3, add(2, 1))
     self.assertEqual(4, add(2, 2))
Пример #16
0
from myfunc import multiply, add, subtr

print(multiply(2,3))
print(add(20, 40))
print(subtr(300, 45))
Пример #17
0
def test_add_Numbers():
    actual = add(-1, 1)
    assert actual == 0