< Summary

Information
Class: Morpho25.Geometry.Material
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Material.cs
Line coverage
72%
Covered lines: 35
Uncovered lines: 13
Coverable lines: 48
Total lines: 147
Line coverage: 72.9%
Branch coverage
64%
Covered branches: 9
Total branches: 14
Branch coverage: 64.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_IDs()100%1100%
.ctor(...)100%1100%
ToString()100%10%
Serialize()100%1100%
Deserialize(...)100%1100%
Equals(...)50%675%
Equals(...)50%475%
GetHashCode()100%10%
op_Equality(...)100%4100%
op_Inequality(...)100%1100%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\Geometry\Material.cs

#LineLine coverage
 1using Morpho25.Utility;
 2using Newtonsoft.Json;
 3using System;
 4using System.ComponentModel;
 5using System.ComponentModel.DataAnnotations;
 6using System.Linq;
 7
 8namespace Morpho25.Geometry
 9{
 10    /// <summary>
 11    /// Material class.
 12    /// </summary>
 13    public class Material : IEquatable<Material>
 14    {
 15        [JsonIgnore]
 16        /// <summary>
 17        /// Default wall material.
 18        /// </summary>
 19        public const string DEFAULT_WALL = "000000";
 20        [JsonIgnore]
 21        /// <summary>
 22        /// Default roof material.
 23        /// </summary>
 24        public const string DEFAULT_ROOF = "000000";
 25        [JsonIgnore]
 26        /// <summary>
 27        /// Default green roof material.
 28        /// </summary>
 29        public const string DEFAULT_GREEN_ROOF = " ";
 30        [JsonIgnore]
 31        /// <summary>
 32        /// Default green wall material.
 33        /// </summary>
 34        public const string DEFAULT_GREEN_WALL = " ";
 35        [JsonIgnore]
 36        /// <summary>
 37        /// Default soil material.
 38        /// </summary>
 39        public const string DEFAULT_SOIL = "000000";
 40        [JsonIgnore]
 41        /// <summary>
 42        /// Default plant 2D material.
 43        /// </summary>
 44        public const string DEFAULT_PLANT_2D = "0000XX";
 45        [JsonIgnore]
 46        /// <summary>
 47        /// Default source material.
 48        /// </summary>
 49        public const string DEFAULT_SOURCE = "0000FT";
 50        [JsonIgnore]
 51        /// <summary>
 52        /// Default plant 3D material.
 53        /// </summary>
 54        public const string DEFAULT_PLANT_3D = "0000C2";
 55
 56        [MinLength(1)]
 57        [MaxLength(4)]
 58        [JsonProperty("ids", Required = Required.Always)]
 59        /// <summary>
 60        /// Material array of ID.
 61        /// </summary>
 5962        public string[] IDs { get; private set; }
 63
 64        [JsonConstructor]
 65        /// <summary>
 66        /// Create a new material.
 67        /// </summary>
 68        /// <param name="ids">Array of material code.</param>
 2269        public Material(string[] ids)
 2270        {
 2271            IDs = ids;
 2272        }
 73
 74        /// <summary>
 75        /// String representation of the material.
 76        /// </summary>
 77        /// <returns>String representation.</returns>
 78        public override string ToString()
 079        {
 080            return String.Format("Material::{0}", String.Join(",", IDs));
 081        }
 82
 83        public string Serialize()
 184        {
 185            return JsonConvert.SerializeObject(this);
 186        }
 87
 88        public static Material Deserialize(string json)
 989        {
 90            try
 991            {
 992                return JsonConvert.DeserializeObject<Material>(json);
 93            }
 894            catch (Exception e)
 895            {
 896                throw new Exception(e.Message);
 97            }
 198        }
 99
 100        public bool Equals(Material other)
 6101        {
 6102            if (other == null)
 0103                return false;
 104
 6105            if (other != null
 6106                && Enumerable.SequenceEqual(other.IDs, this.IDs))
 6107                return true;
 108            else
 0109                return false;
 6110        }
 111
 112        public override bool Equals(Object obj)
 6113        {
 6114            if (obj == null)
 0115                return false;
 116
 6117            var materialObj = obj as Material;
 6118            if (materialObj == null)
 6119                return false;
 120            else
 0121                return Equals(materialObj);
 6122        }
 123
 124        public override int GetHashCode()
 0125        {
 126            unchecked
 0127            {
 0128                int hash = 17;
 0129                hash = hash * 23 + IDs.GetHashCode();
 0130                return hash;
 131            }
 0132        }
 133
 134        public static bool operator ==(Material mat1, Material mat2)
 23135        {
 23136            if (((object)mat1) == null || ((object)mat2) == null)
 18137                return Object.Equals(mat1, mat2);
 138
 5139            return mat1.Equals(mat2);
 23140        }
 141
 142        public static bool operator !=(Material mat1, Material mat2)
 6143        {
 6144            return !(mat1 == mat2);
 6145        }
 146    }
 147}