Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1695

Show
Ignore:
Timestamp:
06/29/10 02:58:31 (14 years ago)
Author:
dsimcha
Message:

More unittest improvements for std.range. Most of them are commented out b/c they don't work yet, but fixing them sanely is blocked by DMD bug 3294.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/range.d

    r1694 r1695  
    21422142    int[] a = [ 1, 2, 3 ]; 
    21432143    float[] b = [ 1., 2, 3 ]; 
    21442144    foreach (e; zip(a, b)) 
    21452145    { 
    21462146        assert(e.at!(0) == e.at!(1)); 
    21472147    } 
    21482148    auto z = zip(a, b); 
    21492149    swap(z.front(), z.back()); 
    21502150    //@@@BUG@@@ 
    21512151    //sort!("a.at!(0) < b.at!(0)")(zip(a, b)); 
     2152 
     2153// Horribly broken.  See bugs 4402, 3123 
     2154//    foreach(DummyType1; AllDummyRanges) { 
     2155//        DummyType1 d1; 
     2156//        foreach(DummyType2; AllDummyRanges) { 
     2157//            DummyType2 d2; 
     2158//            auto r = zip(d1, d2); 
     2159// 
     2160//            assert(equal(map!"a.at!0"(r), [1,2,3,4,5,6,7,8,9,10])); 
     2161//            assert(equal(map!"a.at!1"(r), [1,2,3,4,5,6,7,8,9,10])); 
     2162//        } 
     2163//    } 
    21522164} 
    21532165 
    21542166/** 
    21552167Creates a mathematical sequence given the initial values and a 
    21562168recurrence function that computes the popFront value from the existing 
    21572169values. The sequence comes in the form of an infinite forward 
    21582170range. The type $(D Recurrence) itself is seldom used directly; most 
    21592171often, recurrences are obtained by calling the function $(D 
    21602172recurrence). 
    21612173 
     
    26762688 
    26772689/// Ditto 
    26782690FrontTransversal!(RangeOfRanges, opt) frontTransversal( 
    26792691    TransverseOptions opt = TransverseOptions.assumeJagged, 
    26802692    RangeOfRanges) 
    26812693(RangeOfRanges rr) 
    26822694{ 
    26832695    return typeof(return)(rr); 
    26842696} 
    26852697 
     2698unittest { 
     2699    foreach(DummyType; AllDummyRanges) { 
     2700        static if(DummyType.r == ReturnBy.Reference) { // Bug 4403 
     2701            auto dummies = [DummyType.init, DummyType.init]; 
     2702            auto ft = frontTransversal(dummies); 
     2703            assert(equal(ft, [1, 1])); 
     2704        } 
     2705    } 
     2706} 
     2707 
    26862708/** 
    26872709Given a range of ranges, iterate transversally through the the $(D 
    26882710n)th element of each of the enclosed ranges. All elements of the 
    26892711enclosing range must offer random access. 
    26902712 
    26912713Example: 
    26922714---- 
    26932715int[][] x = new int[][2]; 
    26942716x[0] = [1, 2]; 
    26952717x[1] = [3, 4]; 
     
    28142836unittest 
    28152837{ 
    28162838    int[][] x = new int[][2]; 
    28172839    x[0] = [ 1, 2 ]; 
    28182840    x[1] = [3, 4]; 
    28192841    auto ror = transversal(x, 1); 
    28202842    auto witness = [ 2, 4 ]; 
    28212843    uint i; 
    28222844    foreach (e; ror) assert(e == witness[i++]); 
    28232845    assert(i == 2); 
     2846 
     2847    // Test w/o ref return.  Doesn't work due to bug 4404. 
     2848//    alias DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Random) D; 
     2849//    auto drs = [D.init, D.init]; 
     2850//    foreach(num; 0..10) { 
     2851//        auto t = transversal(drs, num); 
     2852//        assert(equal(t, [num + 1, num + 1])); 
     2853//  } 
    28242854} 
    28252855 
    28262856struct Transposed(RangeOfRanges) 
    28272857{ 
    28282858    alias typeof(map!"a.front"(RangeOfRanges.init)) ElementType; 
    28292859 
    28302860    this(RangeOfRanges input) 
    28312861    { 
    28322862        this._input = input; 
    28332863    }