|
| 1 | + |
| 2 | +// Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +// contributor license agreements. See the NOTICE file distributed with |
| 4 | +// this work for additional information regarding copyright ownership. |
| 5 | +// The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +// (the "License"); you may not use this file except in compliance with |
| 7 | +// the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +using Apache.Arrow; |
| 18 | +using Apache.Arrow.Types; |
| 19 | +using System; |
| 20 | +using Xunit; |
| 21 | + |
| 22 | +namespace Apache.Arrow.Tests; |
| 23 | + |
| 24 | +internal class SchemaTests |
| 25 | +{ |
| 26 | + public class Construct |
| 27 | + { |
| 28 | + [Fact] |
| 29 | + public void ThrowsWhenFieldsAreNull() |
| 30 | + { |
| 31 | + Assert.Throws<ArgumentNullException>(() => new Schema(null, null)); |
| 32 | + Assert.Throws<ArgumentNullException>(() => new Schema(null, null, copyCollections: false)); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public class IndexRetrieval |
| 37 | + { |
| 38 | + [Fact] |
| 39 | + public void CanRetrieveFieldIndexByName() |
| 40 | + { |
| 41 | + var field0 = new Field("f0", Int32Type.Default, true); |
| 42 | + var field1 = new Field("f1", Int64Type.Default, true); |
| 43 | + var schema = new Schema([field0, field1], null); |
| 44 | + |
| 45 | + Assert.Equal(0, schema.GetFieldIndex("f0")); |
| 46 | + Assert.Equal(1, schema.GetFieldIndex("f1")); |
| 47 | + Assert.Equal(-1, schema.GetFieldIndex("nonexistent")); |
| 48 | + } |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void CanRetrieveFieldIndexByNonUniqueName() |
| 52 | + { |
| 53 | + var field0 = new Field("f0", Int32Type.Default, true); |
| 54 | + var field1 = new Field("f1", Int64Type.Default, true); |
| 55 | + |
| 56 | + // Repeat fields in the list |
| 57 | + var schema = new Schema([field0, field1, field0, field1], null); |
| 58 | + |
| 59 | + Assert.Equal(0, schema.GetFieldIndex("f0")); |
| 60 | + Assert.Equal(1, schema.GetFieldIndex("f1")); |
| 61 | + Assert.Equal(-1, schema.GetFieldIndex("nonexistent")); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments