コード例 #1
0
        public void Return_Zero_Cost_If_Part_Do_Not_Exists()
        {
            var partDescription = new PartDescription("Part A", "Dublin");

            var inventory = new Inventory();

            PartCost cost = inventory.PreviewCheckOut(partDescription,
                                                      quantity: 2,
                                                      priceStrategy: new FifoPriceStrategy());

            cost.Total.Should().Be(0);
        }
コード例 #2
0
        public void Check_In_Parts()
        {
            const string partType        = "Part A";
            const string warehouse       = "Dublin";
            var          partDescription = new PartDescription(partType, warehouse);

            var inventory = new Inventory();
            var batch     = new Batch(partType, partPrice: 100, quantity: 1);

            inventory.CheckIn(batch, warehouse);

            PartCost cost = inventory.PreviewCheckOut(partDescription,
                                                      quantity: 1,
                                                      priceStrategy: new FifoPriceStrategy());

            cost.Total.Should().Be(100);
        }
コード例 #3
0
        public void Return_Cost_Having_One_Batch_And_Enough_Quantity_Of_That_Part()
        {
            const string partType        = "Part A";
            const string warehouse       = "Dublin";
            var          partDescription = new PartDescription(partType, warehouse);

            var inventory = new Inventory();
            var batch     = new Batch(partType, partPrice: 100, quantity: 2);

            inventory.CheckIn(batch, warehouse);

            PartCost cost = inventory.PreviewCheckOut(partDescription,
                                                      quantity: 2,
                                                      priceStrategy: new FifoPriceStrategy());

            cost.Total.Should().Be(200);
        }
コード例 #4
0
        public void Return_Cost_Having_Several_Batches_Of_That_Part_With_LIFO_Strategy()
        {
            const string partType        = "Part A";
            const string warehouse       = "Dublin";
            var          partDescription = new PartDescription(partType, warehouse);

            var inventory = new Inventory();
            var batch1    = new Batch(partType, partPrice: 100, quantity: 2);
            var batch2    = new Batch(partType, partPrice: 150, quantity: 4);

            inventory.CheckIn(batch1, warehouse);
            inventory.CheckIn(batch2, warehouse);

            PartCost cost = inventory.PreviewCheckOut(partDescription,
                                                      quantity: 5,
                                                      priceStrategy: new LifoPriceStrategy());

            cost.Total.Should().Be(700);
        }
コード例 #5
0
        public void Check_Out_Parts()
        {
            const string partType        = "Part A";
            const string warehouse       = "Dublin";
            var          partDescription = new PartDescription(partType, warehouse);

            var inventory = new Inventory();
            var batch1    = new Batch(partType, partPrice: 100, quantity: 2);
            var batch2    = new Batch(partType, partPrice: 100, quantity: 4);

            inventory.CheckIn(batch1, warehouse);
            inventory.CheckIn(batch2, warehouse);

            inventory.CheckOut(partDescription,
                               quantity: 5,
                               priceStrategy: new LifoPriceStrategy());

            inventory.GetQuantity(partDescription).Should().Be(1);
        }
コード例 #6
0
        public void FirstWordTest_GivenSpace()
        {
            var desc = new PartDescription("BOLT THREADED");

            Assert.Equal("BOLT", desc.FirstWord());
        }
コード例 #7
0
 public static bool IsHybridLines(this PartDescription description)
 {
     return(description.StartsWith("LINE") && description.Contains("HYBR"));
 }
コード例 #8
0
 public static bool IsHose(this PartDescription description)
 {
     return(description.StartsWith("HOSE"));
 }
コード例 #9
0
 public static bool IsGasket(this PartDescription description)
 {
     return(description.StartsWith("GASKET"));
 }
コード例 #10
0
 public static bool IsZinc(this PartDescription description)
 {
     return(description.Contains("ZINC"));
 }
コード例 #11
0
 public static bool IsNut(this PartDescription description)
 {
     return(description.StartsWith("NUT"));
 }
コード例 #12
0
 public static bool IsTurbocharger(this PartDescription description)
 {
     return(description.StartsWith("TURBO"));
 }
コード例 #13
0
 public static bool IsPumpGroup(this PartDescription description)
 {
     return(description.StartsWith("PUMP GP"));
 }
コード例 #14
0
 public static bool IsControlGroup(this PartDescription description)
 {
     return(description.StartsWith("CONTROL GP"));
 }
コード例 #15
0
 public static bool IsCable(this PartDescription description)
 {
     return(description.StartsWith("CABLE AS"));
 }
コード例 #16
0
 public static bool IsSpacer(this PartDescription description)
 {
     return(description.StartsWith("SPACER"));
 }
コード例 #17
0
 public static bool IsBolt(this PartDescription description)
 {
     return(description.StartsWith("BOLT"));
 }
コード例 #18
0
 public static bool IsBearingOrBushing(this PartDescription description)
 {
     return(description.StartsWith("BUSHING") ||
            description.StartsWith("BEARING"));
 }
コード例 #19
0
 public static bool IsLocknut(this PartDescription description)
 {
     return(description.StartsWith("LOCKNUT"));
 }
コード例 #20
0
 public static bool IsCompositePart(this PartDescription description)
 {
     return(description.Contains(" AS") ||
            description.Contains(" GP") ||
            description.Contains(" AR"));
 }
コード例 #21
0
 public static bool IsSeal(this PartDescription description)
 {
     return(description.StartsWith("SEAL"));
 }
コード例 #22
0
 public static bool IsKitPart(this PartDescription description)
 {
     return(description.StartsWith("KIT-"));
 }
コード例 #23
0
 public static bool IsGrommet(this PartDescription description)
 {
     return(description.StartsWith("GROMMET"));
 }
コード例 #24
0
 public static bool IsSensor(this PartDescription description)
 {
     return(description.StartsWith("SENSOR"));
 }
コード例 #25
0
 public static bool IsSwitch(this PartDescription description)
 {
     return(description.StartsWith("SWITCH AS") ||
            description.StartsWith("SWITCH GP"));
 }
コード例 #26
0
 public static bool IsHarnessAs(this PartDescription description)
 {
     return(description.StartsWith("HARNESS AS") ||
            description.StartsWith("WIRE AS") ||
            description.StartsWith("CABLE AS"));
 }
コード例 #27
0
 public static bool IsIntakeExhaustValve(this PartDescription description)
 {
     return(description.StartsWith("VALVE-IN") || description.StartsWith("VALVE-EX"));
 }
コード例 #28
0
 public static bool IsArrangement(this PartDescription description)
 {
     return(description.Contains(" AR-") || description.ToString().EndsWith(" AR"));
 }
コード例 #29
0
        public static ModelMesh[] ProcessContainer(IModelResourceContainer container, ModelShaderReference[] shaders, string note = null)
        {
            var parts = new List <PartDescription>((int)container.Header.PartInfoCount);

            var        verts   = new VertexFormat[container.VertexCount];
            Span <int> indices = new int[container.Header.IndexCount];

            var currentResource = 0;

            // process part info 0 resource
            if (container.Header.PartInfoCount > 0)
            {
                var partData = container.Resources[currentResource].Data.Span;

                for (var i = 0; i < container.Header.PartInfoCount; i++)
                {
                    var start = i * 72;

                    var elementType = (MeshElementType)partData.ReadUInt16At(start + 2);
                    var matId       = partData.ReadUInt16At(start + 4);
                    var indexStart  = partData.ReadUInt16At(start + 6);
                    var indexCount  = partData.ReadUInt16At(start + 8);

                    var partDescription = new PartDescription(indexStart, indexCount, shaders[matId].ShaderId, elementType);

                    parts.Add(partDescription);
                }

                currentResource++;
            }

            // process part info 2 resource
            if (container.Header.PartInfo2Count > 0)
            {
                // Not positive on what this is for, last ushort of the 8 bytes looks to be part index
                currentResource++;
            }

            // process part info 3 resource
            if (container.Header.PartInfo3Count > 0)
            {
                currentResource++;
            }

            // process indicies resource
            if (container.Header.IndexCount > 0)
            {
                var data = container.Resources[currentResource].Data.Span;

                for (var i = 0; i < container.Header.IndexCount; i++)
                {
                    indices[i] = data.ReadUInt16At(i * 2);
                }

                currentResource++;
            }

            // process unknown resource
            if (container.Header.UknownDataLength > 0)
            {
                currentResource++;
            }

            // process unknown resource
            if (container.Header.UknownIndiciesCount > 0)
            {
                currentResource++;
            }

            // process Vertex Attribute Hint resource
            if (container.Header.VertexComponentCount > 0)
            {
                currentResource++;
            }

            // process vertex attribute resources
            if (container.Header.VertexComponentCount > 0)
            {
                if (container.Header.VertexComponentCount >= 1)
                {
                    var posData = container.Resources[currentResource].Data.Span;

                    // TODO: Find out why stride can be different/ how to know other than this method
                    var itemStride = posData.Length / container.VertexCount;

                    for (var i = 0; i < container.VertexCount; i++)
                    {
                        var vert = new VertexFormat();

                        vert.Position = posData.ReadVec3At(i * itemStride);

                        verts[i] = vert;
                    }

                    currentResource++;
                }

                if (container.Header.VertexComponentCount >= 2)
                {
                    var texData = container.Resources[currentResource].Data.Span;

                    for (var i = 0; i < container.VertexCount; i++)
                    {
                        var vert = verts[i];

                        vert.TexCoords = texData.ReadVec2At(i * 8);

                        verts[i] = vert;
                    }

                    currentResource++;
                }

                if (container.Header.VertexComponentCount >= 3)
                {
                    var tbnData = container.Resources[currentResource].Data.Span;

                    for (var i = 0; i < container.VertexCount; i++)
                    {
                        var vert = verts[i];

                        var start = i * 36;
                        vert.Normal    = tbnData.ReadVec3At(start);
                        vert.Bitangent = tbnData.ReadVec3At(start + 12);
                        vert.Tangent   = tbnData.ReadVec3At(start + 24);

                        verts[i] = vert;
                    }

                    currentResource++;
                }
            }

            var meshes = new List <ModelMesh>(parts.Count);

            foreach (var part in parts)
            {
                meshes.Add(new ModelMesh
                {
                    Verticies   = verts,
                    Indices     = indices.Slice(part.IndexStart, part.IndexCount).ToArray(),
                    Shader      = part.Shader,
                    ElementType = part.ElementType,
                    Note        = note
                });
            }

            return(meshes.ToArray());
        }
コード例 #30
0
 public static bool IsWasher(this PartDescription description)
 {
     return(description.StartsWith("WASHER") && !description.StartsWith("WASHER-THR"));
 }