Ejemplo n.º 1
0
    def test_parse_rdump_value(self):
        s1 = 'structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16),.Dim=c(2,8))'
        v_s1 = parse_rdump_value(s1)
        self.assertEqual(v_s1.shape, (2, 8))
        self.assertEqual(v_s1[1, 0], 2)
        self.assertEqual(v_s1[0, 7], 15)

        s2 = 'structure(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),.Dim=c(1,16))'
        v_s2 = parse_rdump_value(s2)
        self.assertEqual(v_s2.shape, (1, 16))

        s3 = 'structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16),.Dim = c(8, 2))'
        v_s3 = parse_rdump_value(s3)
        self.assertEqual(v_s3.shape, (8, 2))
        self.assertEqual(v_s3[1, 0], 2)
        self.assertEqual(v_s3[7, 0], 8)
        self.assertEqual(v_s3[0, 1], 9)
        self.assertEqual(v_s3[6, 1], 15)
Ejemplo n.º 2
0
    def test_parse_rdump_value(self):
        struct1 = (
            'structure(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),.Dim=c(2,8))')
        v_struct1 = parse_rdump_value(struct1)
        self.assertEqual(v_struct1.shape, (2, 8))
        self.assertEqual(v_struct1[1, 0], 2)
        self.assertEqual(v_struct1[0, 7], 15)

        struct2 = (
            'structure(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),.Dim=c(1,16))'
        )
        v_struct2 = parse_rdump_value(struct2)
        self.assertEqual(v_struct2.shape, (1, 16))

        struct3 = (
            'structure(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16),.Dim=c(8,2))')
        v_struct3 = parse_rdump_value(struct3)
        self.assertEqual(v_struct3.shape, (8, 2))
        self.assertEqual(v_struct3[1, 0], 2)
        self.assertEqual(v_struct3[7, 0], 8)
        self.assertEqual(v_struct3[0, 1], 9)
        self.assertEqual(v_struct3[6, 1], 15)