Пример #1
0
 public void ReadNullValueLabels()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[3];
         Assert.False(var.GetValueLabels().Any());
     }
 }
Пример #2
0
 public void ReadLabel()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[0];
         Assert.Equal("on butter", var.Label);
     }
 }
Пример #3
0
 public void ReadNullLabel()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[3];
         Assert.Equal(string.Empty, var.Label);
     }
 }
Пример #4
0
 public void GetLongStringValueLabels()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssStringVariable var = (SpssStringVariable)docRead.Variables["longStr"];
         // long strings can never have value labels
         Assert.Equal(0, var.ValueLabels.Count);
     }
 }
Пример #5
0
 public void ReadDecimalPlaces()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssNumericVariable var = docRead.Variables[0] as SpssNumericVariable;
         Assert.NotNull(var); // First variable expected to be numeric.
         Assert.Equal(2, var.WriteDecimal);
     }
 }
Пример #6
0
 public void SetStringTooLong()
 {
     using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
     {
         SpssStringVariable var = (SpssStringVariable)docAppend.Variables["charLabels"];
         Debug.Assert(var.Length == 8);
         SpssCase row = docAppend.Cases.New();
         Assert.Throws <ArgumentOutOfRangeException>(() => row["charLabels"] = new string('a', var.Length + 1));
     }
 }
Пример #7
0
 public void OpenExistingDocumentForAppend()
 {
     using (SpssDataDocument doc = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
     {
         Assert.Equal(SpssFileAccess.Append, doc.AccessMode);
         Assert.False(doc.IsClosed, "Newly opened document claims to be closed.");
         Assert.Equal(TestBase.AppendFilename, doc.Filename);
         Assert.False(doc.IsAuthoringDictionary, "Cannot be authoring dictionary when appending data.");
     }
 }
Пример #8
0
 private static void CreateExampleDocument()
 {
     using (SpssDataDocument doc = SpssDataDocument.Create("example.sav")) {
         CreateMetaData(doc);
         CreateData(doc);
     }
     Console.WriteLine("Examine example.sav for the results.");
     Console.WriteLine("SPSS file reading demo:");
     using (SpssDataDocument doc = SpssDataDocument.Open(GetFileName(), SpssFileAccess.Read)) {
         PrintMetaData(doc);
         PrintData(doc);
     }
 }
Пример #9
0
        public static void ReadSpssFile()
        {
            using (var doc = SpssDataDocument.Open("t.sav", SpssFileAccess.Append)) {
                SpssNumericVariable accuracy = new SpssNumericVariable {
                    Name             = $"Accuracy",
                    Label            = $"Distance in pixels from target",
                    MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT
                };
                doc.Variables.Add(accuracy);

                SpssStringVariable var = (SpssStringVariable)doc.Variables["someLabel"];

                SpssCase row = doc.Cases.New();
                row[$"Accuracy"] = new string('a', var.Length + 1);
            }
        }
Пример #10
0
        public void SetMissingValueDateByNull()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex       = row.Position;
                row["dateVar"] = null;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                DateTime?val = (DateTime?)row["dateVar"];
                Assert.False(val.HasValue);
            }
        }
Пример #11
0
        public void SetMissingValueNumeric()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex   = row.Position;
                row["num"] = double.NaN;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                double   val = (double)row["num"];
                Assert.Equal(double.NaN, val);
            }
        }
Пример #12
0
 public TestBase()
 {
     try
     {
         docRead   = SpssDataDocument.Open(GoodFilename, SpssFileAccess.Read);
         docAppend = SpssDataDocument.Open(AppendFilename, SpssFileAccess.Append);
         if (File.Exists(DisposableFilename))
         {
             File.Delete(DisposableFilename);
         }
         docWrite = SpssDataDocument.Create(DisposableFilename);
     }
     catch
     {
         docRead?.Dispose();
         docAppend?.Dispose();
         docWrite?.Dispose();
         throw;
     }
 }