Example #1
0
        public void Run_ValidNumbers_UserShouldBeToldToEnterAnotherNumbers()
        {
            var program = new FakeProgram();

            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            {
                Console.SetOut(sw);
                program.Run("1,2,3");
            }

            var expected = new StringBuilder();
            expected.AppendLine("The result is 6");
            expected.AppendLine("Another input please");

            sb.ToString().Should().Be(expected.ToString());
        }
Example #2
0
        public IntPtr clCreateProgramWithSource(IntPtr context, uint count, string[] strings, uint[] lengths,
                                                out OpenClErrorCode errorCodeRet)
        {
            errorCodeRet = clCreateProgramWithSourceErrorCode ?? OpenClErrorCode.Success;
            IntPtr id;

            if (errorCodeRet == OpenClErrorCode.Success)
            {
                id = clCreateProgramWithSourceReturn ?? new IntPtr(1);
                FakePrograms[id] = new FakeProgram(context, strings);
            }
            else
            {
                id = IntPtr.Zero;
            }

            return(id);
        }
Example #3
0
        public void Run_ValidNumbersProvidedTwiceAndEmptyString_TwoSumsAndTwoEnterAnotherNumbersShouldBeOutputToConsole()
        {
            var program = new FakeProgram()
                .WithNumbers("1,2");

            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            {
                Console.SetOut(sw);
                program.Run("1,2,3");
            }

            var expected = new StringBuilder();
            expected.AppendLine("The result is 6");
            expected.AppendLine("Another input please");
            expected.AppendLine("The result is 3");
            expected.AppendLine("Another input please");

            sb.ToString().Should().Be(expected.ToString());
        }
Example #4
0
        public IntPtr clCreateProgramWithBinary(IntPtr context, uint numDevices, IntPtr[] deviceList, uint[] lengths,
                                                IntPtr[] binaries, OpenClErrorCode[] binaryStatus, out OpenClErrorCode errorCodeRet)
        {
            binaryStatus = clCreateProgramWithBinaryBinaryStatus ?? new OpenClErrorCode[deviceList.Length];
            errorCodeRet = clCreateProgramWithBinaryErrorCodeRet ?? OpenClErrorCode.Success;
            var id = clCreateProgramWithBinaryResult ?? new IntPtr(1);

            if (errorCodeRet != OpenClErrorCode.Success)
            {
                return(IntPtr.Zero);
            }

            var deviceBinaries = binaries.Zip(deviceList, (binary, device) => new { binary, device })
                                 .Zip(lengths, (binDev, length) => new { binDev.binary, binDev.device, length })
                                 .Zip(binaryStatus, (binDevLength, status) => new { binDevLength.binary, binDevLength.device, binDevLength.length, status })
                                 .Where(f => f.status == OpenClErrorCode.Success)
                                 .Select(b => Tuple.Create(b.device, new byte[b.length]));

            FakePrograms[id] = new FakeProgram(context, deviceBinaries);
            return(id);
        }
Example #5
0
 static int Main(string[] args) => FakeProgram.FakeMain(args);