예제 #1
0
    def testRandomizeNodes(self):
        random.seed(2)

        K = 2
        master = Master(K, 3)
        master.randomizeNodes()

        self.assertEqual(len(master.nodes), K)
        self.assertEqual(master.nodes[0].data, [5, 4, 0])
        self.assertEqual(master.nodes[1].data, [3, 1, 2])
예제 #2
0
    def test_sortNaive_onenode(self):
        random.seed(2)

        K = 1
        master = Master(K, 3)
        master.randomizeNodes()

        merge = NMerge()
        merge.sortNaive(master)

        self.assertEqual(len(master.nodes), K)
        self.assertEqual(master.nodes[0].data, [0, 1, 2])
예제 #3
0
    def test_sortNaive_nodata(self):
        random.seed(2)

        K = 3
        master = Master(K, 0)
        master.randomizeNodes()

        merge = NMerge()
        merge.sortNaive(master)

        self.assertEqual(len(master.nodes), K)
        self.assertEqual(master.nodes[0].data, [])
        self.assertEqual(master.nodes[1].data, [])
        self.assertEqual(master.nodes[2].data, [])
예제 #4
0
    def test_findBufferMin(self):
        random.seed(2)

        K = 3
        master = Master(K, 2)
        master.buffer = [3, 1, 2]

        merge = NMerge()
        merge.master = master
        merge.nodeDataIndex = [0, 3, 1]

        merge.findBufferMin()

        self.assertEqual(merge.bufferMinIndex, 2)
예제 #5
0
    def test_sortNaive_normal(self):
        random.seed(2)

        K = 3
        master = Master(K, 3)
        master.randomizeNodes()

        #         master.printData()

        merge = NMerge()
        merge.sortNaive(master)

        self.assertEqual(len(master.nodes), K)
        self.assertEqual(master.nodes[0].buffer, [0, 1, 2])
        self.assertEqual(master.nodes[1].buffer, [3, 4, 5])
        self.assertEqual(master.nodes[2].buffer, [6, 7, 8])
예제 #6
0
    def test_initMasterBuffer(self):
        random.seed(2)

        K = 2
        master = Master(K, 2)
        master.randomizeNodes()

        merge = NMerge()
        merge.master = master

        merge.initMasterBuffer()

        self.assertEqual(len(master.nodes), K)
        self.assertEqual(master.nodes[0].data, [3, 2])
        self.assertEqual(master.nodes[1].data, [0, 1])

        self.assertEqual(master.buffer, [3, 0])
        self.assertEqual(merge.nodeDataIndex, [0, 0])
예제 #7
0
                    action='store',
                    required=False,
                    default=5,
                    help='Number of workers')

args = parser.parse_args()

logging.basicConfig(level=logging.DEBUG)

try:
    starttime = time.time()

    N = int(args.N)
    K = int(args.K)

    master = Master(K, N)
    master.randomizeNodes()

    print "Before sorting"
    master.printData()

    merge = NMerge()
    merge.sortNaive(master)

    print "After sorting"
    master.printData()

    timeDiff = (time.time() - starttime) * 1000.0
    print "Calculation time: {:13.8f}ms".format(timeDiff)
finally:
    pass