コード例 #1
0
    def test_rand(self):
        def known_diamond(n):
            if n % 2 == 0 or n < 0:
                return None
            result = []

            def append(c, n, nl):
                for _ in range(n):
                    result.append(c)
                if nl:
                    result.append('\n')

            indent = n // 2
            for i in range(indent, 0, -1):
                append(' ', i, False)
                append('*', n - 2 * i, True)
            append('*', n, True)
            for i in range(1, indent + 1):
                append(' ', i, False)
                append('*', n - 2 * i, True)
            return "".join(result)

        from random import randrange as rand

        for _ in range(25):
            n = rand(1, 20) if rand(4) else rand(-20, 5)
            exp = known_diamond(n)
            self.assertEqual(diamond(n), exp)
コード例 #2
0
def get_road_mask(im: np.ndarray) -> np.ndarray:
    # Gaussian blur to make the road surface look more even
    im_blur = gaussian_filter(im, sigma=1)

    # K-Means clustering to get road
    im_c, kmeans = cluster_image(im_blur)
    mean_labels = np.mean(kmeans.cluster_centers_, axis=1) / 255
    midtone_label = np.argsort(mean_labels)[1]
    midtone_value = kmeans.cluster_centers_[midtone_label] / 255

    # midtone mask (assume midtone contains road)
    mask = (im_c == midtone_value)
    mask = mask.astype('float64').mean(axis=2)

    # Binary closing - close noise
    kernel = diamond(3)
    mask_closed = binary_closing(mask, kernel)

    # Binary opening - disconnect thinly connected parts
    mask_closed = binary_opening(mask, kernel)

    # Connected components
    cc = measure.label(mask_closed, background=0)

    # Assume the largest group is the road
    largest_cc = get_largest_component(cc)
    mask_main_cc = np.zeros(cc.shape)
    mask_main_cc[cc == largest_cc] = 1

    # Get connected components of the reverse mask to fill in holes
    reverse_mask = 1 - mask_main_cc
    cc_rev = measure.label(reverse_mask, background=0)
    cc_rev_flat = cc_rev.reshape(-1)
    unique_labels = np.unique(cc_rev)
    counts = []
    for label in unique_labels:
        counts.append(len(cc_rev_flat[cc_rev_flat == label]))
    max_size = np.max(counts)
    for label in unique_labels:
        if counts[label] < max_size:
            cc_rev[cc_rev == label] = 0

    cc_rev[cc_rev > 0] = 1
    final_mask = 1 - cc_rev
    final_mask = final_mask.astype(np.float)
    return final_mask
コード例 #3
0
def test_diamond(len, expected):
    assert np.array_equal(diamond(len), expected) is True
コード例 #4
0
pen1.circle(100)
pen1.end_fill()
pen2.write("KP", font=('Candara', 70))

pen1.up()
pen1.goto(-250, -150)
pen1.down()
pen1.write("""1. Blackjack
2. Lucky 7
3. Pattern 1
4. Pattern 2""",
           font=("Candara", 20))

while True:
    k = input('Enter Choice ')
    if k == 1:
        blackjack.blackjack()
    elif k == 2:
        lucky7.lucky7()
    elif k == 3:
        triangle.triangle()
    else:
        diamond.diamond()
    print ""
    x = raw_input('You want to continue here (y/n)? ')
    if x == 'n':
        print "Thank You For Playing"
        break
    else:
        True
コード例 #5
0
ファイル: test_diamond.py プロジェクト: thehyve/coding-dojo
 def test_B_diamond(self):
     self.assertEqual(diamond('B'), ' A \nB B\n A ')
コード例 #6
0
ファイル: tests.py プロジェクト: mtecles/diamond
 def test_when_a_return_a(self):
     params = 'a'
     result = diamond(params)
     self.assertEquals(result, 'a\n')
コード例 #7
0
def test_a_diamond():
    assert diamond("A") == ["A"]
コード例 #8
0
def test_c_diamond():
    assert diamond("C") == ["  A  ", " B B ", "C   C", " B B ", "  A  "]
コード例 #9
0
	def test_receive_D_and_return_a_diamond_with_A_B_C_D(self):
		returned = diamond.diamond('D')

		expected = '   A\n  B B\n C   C\nD     D\n C   C\n  B B\n   A'

		self.assertEquals(returned, expected)
コード例 #10
0
	def test_receive_B_and_return_a_diamond_with_A_and_B(self):
		returned = diamond.diamond('B')

		expected = ' A\nB B\n A'

		self.assertEquals(returned, expected)
コード例 #11
0
def test_diamond_invalid_input(n, expected):
    """Check if function diamond returns None on an invalid input."""

    assert diamond(n) == expected
コード例 #12
0
def test_highher_n_value():
    """Test for n = 9."""

    assert diamond(9) == '    *\n   ***\n  *****\n *******\n*********\n' \
                         ' *******\n  *****\n   ***\n    *\n'
コード例 #13
0
def test_basic_shape():
    """Test diamond production for n = 3."""

    assert diamond(3) == ' *\n***\n *\n'
コード例 #14
0
 def test(self):
     self.assertEqual(diamond(3), " *\n***\n *\n")
     self.assertEqual(diamond(0), None)
     self.assertEqual(diamond(2), None)
     self.assertEqual(diamond(-1), None)
     self.assertEqual(diamond(-2), None)
コード例 #15
0
	def test_receive_A_and_return_A(self):
		returned = diamond.diamond('A')

		expected = 'A'

		self.assertEquals(returned, expected)
コード例 #16
0
while True:
    print "Choices:"
    print "1    Diamond"
    print "2    Possible Sequences"
    print "3    Removing adjacent similar characters"
    print "4    Calculate Interest from Balance and Rate"
    print "5    Fibonacci Number"
    print "6    Stacks and Queues"
    print "7    Guess the jumbled word"
    print "0   Exit"
    choice = raw_input("Enter choice:")

    if choice == '1':
        print "Diamond:"
        diamond_input = raw_input("Enter Size:")
        diamond.diamond(diamond_input)
    elif choice == '2':
        print "Possible Sequences:"
        sequencer_input = raw_input("Enter sequence")
        sequencer.sequencer(sequencer_input)
    elif choice == '3':
        print "Remove adjacent similar Characters"
        adjacent_input = raw_input("Enter list of strings:")
        print(adjacent.cleaner(adjacent_input))
    elif choice == '4':
        print "Balance growth"
        balance_start = int(raw_input("Enter Starting Balance:"))
        balance_rate = float(raw_input("Enter interest rate:"))
        balance_year = int(raw_input("Enter number of years:"))
        print balance.bal_growth(balance_start, balance_rate, balance_year)
    elif choice == '5':
コード例 #17
0
from circle import circle

if __name__ == '__main__':
  import argparse

  parser = argparse.ArgumentParser(description='Draws art')
  parser.add_argument('program', help='Choose the program', choices=['circle', 'diamond'])
  parser.add_argument('size', help='The size of the art', default=17, type=int)
  parser.add_argument('-o', '--out', help='Output to a file', type=argparse.FileType('w+'), default=sys.stdout)
  parser.add_argument('-f', '--filled', help='Character to use to fill a point', default='X')
  parser.add_argument('-e', '--empty', help='Character to use to fill empty points', default=' ')
  parser.add_argument('-w', '--width', help='Number of -e characters to put between points', default=1, type=int)
  parser.add_argument('-l', '--line-height', help='Number of newlines between each line', default=1, type=int)

  args = parser.parse_args()

  end = args.empty * args.width

  if (args.program == 'circle'):
    d = circle(args.size, args.filled, args.empty)

  if (args.program == 'diamond'):
    d = diamond(args.size, args.filled, args.empty)

  def p(c):
    print(c, end='', file=args.out, flush=True)

  for y in d:
    for x in y:
      p(x + end)
    p('\n' * args.line_height)
コード例 #18
0
def test_d_diamond():
    assert diamond("D") == [
        "   A   ", "  B B  ", " C   C ", "D     D", " C   C ", "  B B  ",
        "   A   "
    ]
コード例 #19
0
ファイル: test_diamond.py プロジェクト: thehyve/coding-dojo
 def test_C_diamond(self):
     self.assertEqual(diamond('C'), '  A  \n B B \nC   C\n B B \n  A  ')
コード例 #20
0
def test_b_diamond():
    assert diamond("B") == [" A ", "B B", " A "]
コード例 #21
0
ファイル: test_diamond.py プロジェクト: thehyve/coding-dojo
 def test_A_diamond(self):
     self.assertEqual(diamond('A'), 'A')
コード例 #22
0
ファイル: tests.py プロジェクト: mtecles/diamond
 def test_when_c_return_diamond(self):
     params = 'c'
     result = diamond(params)
     self.assertEquals(result, '  a  \n b b \nc   c\n b b \n  a  \n')
コード例 #23
0
ファイル: all_test.py プロジェクト: Santasy/PortafolioINFO229
def test_diamond(car, output):
    assert diamond(car) == output