예제 #1
0
        private UrlGenerator ChooseGenerator(string comicUrl)
        {
            var aComic = new ComicUri(comicUrl);

            UrlGenerator gen;

            if (aComic.Indices.Length == 1)
            {
                // option A or B

                var dateCount = new DateGenerator(aComic);

                // identify if it's a valid date
                if (dateCount.Format != DateType.NotRecognized)
                {
                    // B of some kind
                    gen = dateCount;
                }
                else
                {
                    // A of some kind
                    var seqCount = new SequentialGenerator(aComic);
                    gen = seqCount;
                }
            }
            else
            {
                // option C or D
                throw new NotImplementedException();
            }
            return(gen);
        }
        public void GenerateSome()
        {
            var xkcdPages = new string[7];
            xkcdPages [0] = "http://xkcd.com/608";
            xkcdPages [1] = "http://xkcd.com/609";
            xkcdPages [2] = "http://xkcd.com/610";
            xkcdPages [3] = "http://xkcd.com/611";
            xkcdPages [4] = "http://xkcd.com/612";
            xkcdPages [5] = "http://xkcd.com/613";
            xkcdPages [6] = "http://xkcd.com/614";
            var comic = new ComicUri ("http://xkcd.com/608");
            var seqCount = new SequentialGenerator (comic);
            Assert.AreEqual (xkcdPages, seqCount.GenerateSome ());

            xkcdPages = new string[7];
            xkcdPages [0] = "http://xkcd.com/3";
            xkcdPages [1] = "http://xkcd.com/4";
            xkcdPages [2] = "http://xkcd.com/5";
            xkcdPages [3] = "http://xkcd.com/6";
            xkcdPages [4] = "http://xkcd.com/7";
            xkcdPages [5] = "http://xkcd.com/8";
            xkcdPages [6] = "http://xkcd.com/9";
            comic = new ComicUri ("http://xkcd.com/5");
            seqCount = new SequentialGenerator (comic);
            Assert.AreEqual (xkcdPages, seqCount.GenerateSome ());
        }
        public void GenerateRange()
        {
            var xkcdPages = new string[5];
            xkcdPages [0] = "http://xkcd.com/610";
            xkcdPages [1] = "http://xkcd.com/611";
            xkcdPages [2] = "http://xkcd.com/612";
            xkcdPages [3] = "http://xkcd.com/613";
            xkcdPages [4] = "http://xkcd.com/614";
            var comic = new ComicUri ("http://xkcd.com/614");
            var xkcdRules = new SequentialGenerator (comic);
            Assert.AreEqual (xkcdPages, xkcdRules.Generate (Enumerable.Range (610, 5)));

            xkcdPages = new string[5];
            xkcdPages [0] = "http://xkcd.com/1";
            xkcdPages [1] = "http://xkcd.com/2";
            xkcdPages [2] = "http://xkcd.com/3";
            xkcdPages [3] = "http://xkcd.com/4";
            xkcdPages [4] = "http://xkcd.com/5";
            comic = new ComicUri ("http://xkcd.com/614");
            xkcdRules = new SequentialGenerator (comic);
            Assert.AreEqual (xkcdPages, xkcdRules.Generate (Enumerable.Range (1, 5)));

            xkcdPages = new string[5];
            xkcdPages [0] = "http://xkcd.com/001";
            xkcdPages [1] = "http://xkcd.com/002";
            xkcdPages [2] = "http://xkcd.com/003";
            xkcdPages [3] = "http://xkcd.com/004";
            xkcdPages [4] = "http://xkcd.com/005";
            comic = new ComicUri ("http://xkcd.com/614");
            xkcdRules = new SequentialGenerator (comic);
            xkcdRules.Padded = true;
            Assert.AreEqual (xkcdPages, xkcdRules.Generate (Enumerable.Range (1, 5)));
        }
 public void IdentifyImgXkcd()
 {
     var url = "http://xkcd.com/614";
     var xkcdRules = new SequentialGenerator (url);
     var actualUrl = "http://imgs.xkcd.com/comics/woodpecker.png";
     string result = null;
     Assert.AreEqual (1, UrlGenerator.IdentifyImg (xkcdRules.Generate (Enumerable.Range (614, 3)), out result));
     Assert.AreEqual (actualUrl, result);
 }
 public void IdentifyImgSmbc()
 {
     string url = "http://www.smbc-comics.com/index.php?db=comics&id=614";
     var smbcRules = new SequentialGenerator (url);
     var actualUrl = "http://www.smbc-comics.com/comics/20061011.gif";
     var actualUrl2 = "http://zs1.smbc-comics.com/comics/20061011.gif";
     string result = null;
     Assert.AreEqual (2, UrlGenerator.IdentifyImg (smbcRules.Generate (Enumerable.Range (614, 2)), out result));
     Assert.IsTrue (result.Equals (actualUrl) || result.Equals (actualUrl2));
 }
 public void IdentifyImgIrregularWebcomic()
 {
     var pageUrl = "http://www.irregularwebcomic.net/32.html";
     var fullComicUrl = "http://www.irregularwebcomic.net/comics/irreg0032.jpg";
     var seqGen = new SequentialGenerator (pageUrl);
     var somePageUrls = seqGen.GenerateSome ();
     foreach (var x in somePageUrls) {
         Console.WriteLine (x);
     }
     string imgUrl;
     var index = UrlGenerator.IdentifyImg (somePageUrls, out imgUrl);
     Assert.AreEqual (1, index);
     // depends on what GenerateSome provides
     Assert.AreEqual (fullComicUrl, imgUrl);
 }
예제 #7
0
        private UrlGenerator ChooseGenerator(string comicUrl)
        {
            var aComic = new ComicUri (comicUrl);

            UrlGenerator gen;

            if (aComic.Indices.Length == 1) {
                // option A or B

                var dateCount = new DateGenerator (aComic);

                // identify if it's a valid date
                if (dateCount.Format != DateType.NotRecognized) {
                    // B of some kind
                    gen = dateCount;
                } else {
                    // A of some kind
                    var seqCount = new SequentialGenerator (aComic);
                    gen = seqCount;
                }
            } else {
                // option C or D
                throw new NotImplementedException ();
            }
            return gen;
        }
 public void ImgIndexXkcd()
 {
     var url = "http://xkcd.com/614";
     var urlGen = new SequentialGenerator (url);
     Assert.AreEqual (1, urlGen.ImgIndex);
 }
 public void ImgIndexSmbc()
 {
     string url = "http://www.smbc-comics.com/index.php?db=comics&id=614";
     var urlGen = new SequentialGenerator (url);
     Assert.AreEqual (2, urlGen.ImgIndex);
 }
        public void Start()
        {
            var url = "http://xkcd.com/614";
            var seqCo = new SequentialGenerator (url);
            Assert.AreEqual ("1", seqCo.Start);
            Assert.IsFalse (seqCo.Padded);

            var newStart = "600";
            seqCo = new SequentialGenerator (url);
            seqCo.Start = newStart;
            Assert.AreEqual (newStart, seqCo.Start);
            Assert.IsFalse (seqCo.Padded);

            newStart = "006";
            seqCo.Start = newStart;
            Assert.AreEqual (newStart, seqCo.Start);
            Assert.IsTrue (seqCo.Padded);
        }
        public void Padded()
        {
            // figure out the real answer
            var url = "http://xkcd.com/614";
            var seqCo = new SequentialGenerator (new ComicUri (url));
            Assert.IsFalse (seqCo.Padded);

            // we set it
            seqCo.Padded = true;
            Assert.IsTrue (seqCo.Padded);
            seqCo.Padded = false;
            Assert.IsFalse (seqCo.Padded);

            // assume answer from original URL
            url = "http://comic.com/01";
            seqCo = new SequentialGenerator (url);
            Assert.IsTrue (seqCo.Padded);

            // assume answer from original URL
            url = "http://comic.com/1";
            seqCo = new SequentialGenerator (url);
            Assert.IsFalse (seqCo.Padded);
        }