예제 #1
0
        public void TryEnqueue_fails_when_at_capacity()
        {
            var q = new CircularQueue<int>(1);
            Assume.That(() => q.TryEnqueue(0));

            Check.That(() => !q.TryEnqueue(1));
        }
예제 #2
0
        public void TryEnqueue_fails_if_write_catches_up_to_read()
        {
            var q = new CircularQueue<int>(2);
            int ignored;
            Assume.That(() => q.TryEnqueue(0));
            Assume.That(() => q.TryDeque(out ignored));

            Assume.That(() => q.TryEnqueue(0));
            Assume.That(() => q.TryEnqueue(1));
            Check.That(() => !q.TryEnqueue(2));
        }
예제 #3
0
        public void is_first_in_first_out()
        {
            var q = new CircularQueue<int>(2);

            Assume.That(() => q.TryEnqueue(0));
            Assume.That(() => q.TryEnqueue(1));

            int value;
            Check.That(
                () => q.TryDeque(out value) && value == 0,
                () => q.TryDeque(out value) && value == 1
            );
        }
예제 #4
0
파일: Program.cs 프로젝트: drunkcod/Cone
        static int Main(string[] args)
        {
            if(args.Length == 0)
                return DisplayUsage();

            string configPath = null;
            string[] assemblyPaths;
            try {
                var config = ConesoleConfiguration.Parse(args);
                configPath = config.ConfigPath;
                assemblyPaths = config.AssemblyPaths;
            } catch {
                return DisplayUsage();
            }

            if(args.Contains("--debug"))
                Debugger.Launch();

            if(!args.Contains("--autotest"))
                return RunTests(args, assemblyPaths, configPath);

            var q = new CircularQueue<string>(32);
            var watchers = assemblyPaths.ConvertAll(path => {
                var watcher = new FileSystemWatcher {
                    Path = Path.GetDirectoryName(path),
                    Filter = Path.GetFileName(path),
                };

                watcher.Changed += (_, e) => {
                    while(!q.TryEnqueue(e.FullPath))
                        Thread.Yield();
                };
                watcher.EnableRaisingEvents = true;
                return watcher;

            });

            Console.WriteLine("Running in autotest mode, press any key to quit.");

            ParameterizedThreadStart workerRunTests = x => {
                var paths = (string[])x;
                Console.WriteLine("[{0}] Change(s) detected in: {1}\n\t", DateTime.Now.ToString("HH:mm:ss"), string.Join("\n\t", paths));
                RunTests(args, paths, configPath);
            };
            var worker = new Thread(workerRunTests);
            worker.Start(assemblyPaths);

            var changed = new HashSet<string>();
            var cooldown = Stopwatch.StartNew();
            do {
                string value;
                while (q.TryDeque(out value)) {
                    changed.Add(value);
                    cooldown.Restart();
                }
                if(changed.Count > 0 && worker.Join(25) && cooldown.Elapsed.TotalMilliseconds > 100) {
                    worker = new Thread(workerRunTests);
                    worker.Start(changed.ToArray());
                    changed.Clear();
                } else Thread.Sleep(25);
            } while(!Console.KeyAvailable);
            worker.Join();
            return 0;
        }