File size: 22,579 Bytes
d5bfab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
use std::path::{Path,PathBuf};
use serde::Deserialize;
use std::fs;

const DEFAULT_CONFIG: &'static str = include_str!("default_config.toml");

#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Eq)]
#[serde(tag = "type", content = "content")]
pub enum MinerCPUStrategy {
    #[serde(rename = "min")]
    Min,
    #[serde(rename = "half")]
    Half,
    #[serde(rename = "max")]
    Max,
    #[serde(rename = "cpu")]
    CPU { count: u16 },
}

#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Eq)]
#[serde(tag = "type", content = "content")]
pub enum MinerFilterMode {
    /// Search only for `new` programs. Don't waste time mining for `existing` programs.
    #[serde(rename = "new")]
    New,

    /// Search for both `new` programs and `existing` programs.
    /// 
    /// The majority of programs found are improvements to `existing` programs.
    /// It's time consuming comparing performance between the `new` program vs the `existing` program,
    /// and picking most optimal program.
    /// 
    /// The minority programs found are `new` programs.
    /// No time is spent on comparing performance, since there is no `existing` program.
    #[serde(rename = "all")]
    All,
}

#[derive(Clone, Debug)]
pub struct Config {
    basedir: PathBuf,
    loda_programs_repository: PathBuf,
    loda_rust_repository: PathBuf,
    loda_rust_executable: PathBuf,
    miner_sync_executable_command_windows: String,
    miner_sync_executable: PathBuf,
    loda_cpp_executable: PathBuf,
    oeis_stripped_file: PathBuf,
    oeis_names_file: PathBuf,
    loda_submitted_by: String,
    miner_metrics_listen_port: u16,
    loda_patterns_repository: PathBuf,
    loda_outlier_programs_repository: PathBuf,
    miner_program_upload_endpoint: String,
    miner_filter_mode: MinerFilterMode,
    miner_cpu_strategy: MinerCPUStrategy,
    arc_repository_data: PathBuf,
    loda_arc_challenge_repository: PathBuf,
}

impl Config {
    pub fn default_config() -> String {
        DEFAULT_CONFIG.to_string()
    }

    pub fn load() -> Self {
        load_config_from_home_dir()
    }

    pub fn basedir(&self) -> PathBuf {
        PathBuf::from(&self.basedir)
    }

    pub fn analytics_oeis_dir(&self) -> PathBuf {
        let path = self.basedir.join("analytics-oeis");
        assert!(path.is_absolute());
        path
    }

    pub fn analytics_arc_dir(&self) -> PathBuf {
        let path = self.basedir.join("analytics-arc");
        assert!(path.is_absolute());
        path
    }

    pub fn mine_event_dir(&self) -> PathBuf {
        let name = Path::new("mine-event");
        let path = self.basedir.join(name);
        assert!(path.is_absolute());
        path
    }

    pub fn postmine_dir(&self) -> PathBuf {
        let name = Path::new("postmine");
        let path = self.basedir.join(name);
        assert!(path.is_absolute());
        path
    }

    pub fn loda_programs_repository(&self) -> PathBuf {
        let path = &self.loda_programs_repository;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    pub fn loda_programs_oeis_dir(&self) -> PathBuf {
        let path = self.loda_programs_repository().join("oeis");
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    pub fn loda_programs_oeis_deny_file(&self) -> PathBuf {
        let path = self.loda_programs_oeis_dir().join("deny.txt");
        assert!(path.is_absolute());
        assert!(path.is_file());
        PathBuf::from(path)
    }

    pub fn oeis_stripped_file(&self) -> PathBuf {
        let path = &self.oeis_stripped_file;
        assert!(path.is_absolute());
        assert!(path.is_file());
        PathBuf::from(path)
    }

    pub fn oeis_names_file(&self) -> PathBuf {
        let path = &self.oeis_names_file;
        assert!(path.is_absolute());
        assert!(path.is_file());
        PathBuf::from(path)
    }

    #[allow(dead_code)]
    pub fn loda_rust_repository(&self) -> PathBuf {
        let path = &self.loda_rust_repository;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    #[allow(dead_code)]
    pub fn loda_rust_executable(&self) -> PathBuf {
        let path = &self.loda_rust_executable;
        assert!(path.is_absolute());
        PathBuf::from(path)
    }

    pub fn miner_sync_executable_command_windows(&self) -> String {
        self.miner_sync_executable_command_windows.clone()
    }

    pub fn miner_sync_executable(&self) -> PathBuf {
        let path = &self.miner_sync_executable;
        assert!(path.is_absolute());
        PathBuf::from(path)
    }

    pub fn loda_cpp_executable(&self) -> PathBuf {
        let path = &self.loda_cpp_executable;
        assert!(path.is_absolute());
        PathBuf::from(path)
    }

    pub fn loda_submitted_by(&self) -> String {
        self.loda_submitted_by.clone()
    }

    pub fn miner_metrics_listen_port(&self) -> u16 {
        let port: u16 = self.miner_metrics_listen_port;
        assert!(port >= 80);
        assert!(port <= 32767);
        return port;
    }

    pub fn similar_programs(&self) -> PathBuf {
        let path = self.basedir.join("similar-programs");
        assert!(path.is_absolute());
        PathBuf::from(path)
    }

    pub fn loda_patterns_repository(&self) -> PathBuf {
        let path = &self.loda_patterns_repository;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    pub fn loda_patterns_repository_simple_constant(&self) -> PathBuf {
        let name = Path::new("simple_constant");
        let path = self.loda_patterns_repository().join(name);
        assert!(path.is_dir());
        path
    }

    pub fn loda_outlier_programs_repository(&self) -> PathBuf {
        let path = &self.loda_outlier_programs_repository;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    pub fn loda_outlier_programs_repository_oeis_divergent(&self) -> PathBuf {
        let name = Path::new("oeis_divergent");
        let path = self.loda_outlier_programs_repository().join(name);
        assert!(path.is_dir());
        path
    }

    pub fn miner_program_upload_endpoint(&self) -> &String {
        &self.miner_program_upload_endpoint
    }

    /// How the time should be spent.
    /// - Mine only for `new` programs.
    /// - Mine for `new` programs and improvements to `existing` programs.
    pub fn miner_filter_mode(&self) -> MinerFilterMode {
        self.miner_filter_mode
    }

    pub fn miner_cpu_strategy(&self) -> MinerCPUStrategy {
        self.miner_cpu_strategy
    }

    #[allow(dead_code)]
    pub fn arc_repository_data(&self) -> PathBuf {
        let path = &self.arc_repository_data;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    #[allow(dead_code)]
    pub fn loda_arc_challenge_repository(&self) -> PathBuf {
        let path = &self.loda_arc_challenge_repository;
        assert!(path.is_absolute());
        assert!(path.is_dir());
        PathBuf::from(path)
    }

    pub fn loda_arc_challenge_repository_programs(&self) -> PathBuf {
        let name = Path::new("programs");
        let path = self.loda_arc_challenge_repository().join(name);
        assert!(path.is_dir());
        path
    }
}

#[derive(Debug, Deserialize)]
struct ConfigFallback {
    loda_programs_repository: String,
    oeis_stripped_file: String,
    loda_rust_repository: String,
    loda_rust_executable: String,
    miner_sync_executable_command_windows: String,
    miner_sync_executable: String,
    loda_cpp_executable: String,
    oeis_names_file: String,
    loda_submitted_by: String,
    miner_metrics_listen_port: u16,
    loda_patterns_repository: String,
    loda_outlier_programs_repository: String,
    miner_program_upload_endpoint: String,
    miner_filter_mode: MinerFilterMode,
    miner_cpu_strategy: MinerCPUStrategy,
    arc_repository_data: String,
    loda_arc_challenge_repository: String,
}

#[derive(Debug, Deserialize)]
struct ConfigCustom {
    loda_programs_repository: Option<String>,
    oeis_stripped_file: Option<String>,
    loda_rust_repository: Option<String>,
    loda_rust_executable: Option<String>,
    miner_sync_executable_command_windows: Option<String>,
    miner_sync_executable: Option<String>,
    loda_cpp_executable: Option<String>,
    oeis_names_file: Option<String>,
    loda_submitted_by: Option<String>,
    miner_metrics_listen_port: Option<u16>,
    loda_patterns_repository: Option<String>,
    loda_outlier_programs_repository: Option<String>,
    miner_program_upload_endpoint: Option<String>,
    miner_filter_mode: Option<MinerFilterMode>,
    miner_cpu_strategy: Option<MinerCPUStrategy>,
    arc_repository_data: Option<String>,
    loda_arc_challenge_repository: Option<String>,
}

fn load_config_from_home_dir() -> Config {
    #![allow(warnings)]
    let homedir: PathBuf = match std::env::home_dir() {
        Some(value) => value,
        None => {
            panic!("Unable to get home_dir!");
        }
    };
    assert!(homedir.is_dir());
    assert!(homedir.is_absolute());

    let basedir_name = Path::new(".loda-rust");
    let basedir: PathBuf = homedir.join(basedir_name);
    if !basedir.is_dir() {
        panic!("Expected a '$HOME/.loda-rust' directory, but got something else. {:?}, Possible solution, remove the thing that uses the same name.", basedir);
    }
    let path_to_config: PathBuf = basedir.join(Path::new("config.toml"));
    if !path_to_config.is_file() {
        panic!("Cannot locate the file '$HOME/.loda-rust/config.toml'");
    }

    let toml_content: String = fs::read_to_string(path_to_config).unwrap();
    config_from_toml_content(toml_content, basedir, homedir)
}

struct SimpleEnvironment {
    homedir: PathBuf,
}

impl SimpleEnvironment {
    fn new(homedir: PathBuf) -> Self {
        assert!(homedir.is_absolute());
        assert!(homedir.is_dir());
        Self {
            homedir: homedir
        }
    }

    fn resolve_path(&self, path_raw: &String) -> PathBuf {
        let path_relativeto_home: String = path_raw.replacen("$HOME/", "", 1);
        let is_relativeto_home = path_relativeto_home.len() != path_raw.len();
        if is_relativeto_home {
            let relative_path = Path::new(&path_relativeto_home);
            return self.homedir.join(relative_path);
        }
        let absolute_path = Path::new(&path_raw);
        assert!(absolute_path.is_absolute());
        PathBuf::from(absolute_path)
    }
}

pub fn config_from_toml_content(toml_content: String, basedir: PathBuf, homedir: PathBuf) -> Config {
    assert!(homedir.is_absolute());
    let simpleenv = SimpleEnvironment::new(homedir);
    let fallback: ConfigFallback = toml::from_str(&DEFAULT_CONFIG).unwrap();
    let custom: ConfigCustom = toml::from_str(&toml_content).unwrap();

    let loda_programs_repository: String = custom.loda_programs_repository.unwrap_or(fallback.loda_programs_repository);
    let oeis_stripped_file: String = custom.oeis_stripped_file.unwrap_or(fallback.oeis_stripped_file);
    let loda_rust_repository: String = custom.loda_rust_repository.unwrap_or(fallback.loda_rust_repository);
    let oeis_names_file: String = custom.oeis_names_file.unwrap_or(fallback.oeis_names_file);
    let loda_rust_executable: String = custom.loda_rust_executable.unwrap_or(fallback.loda_rust_executable);
    let miner_sync_executable_command_windows: String = custom.miner_sync_executable_command_windows.unwrap_or(fallback.miner_sync_executable_command_windows);
    let miner_sync_executable: String = custom.miner_sync_executable.unwrap_or(fallback.miner_sync_executable);
    let loda_cpp_executable: String = custom.loda_cpp_executable.unwrap_or(fallback.loda_cpp_executable);
    let loda_submitted_by: String = custom.loda_submitted_by.unwrap_or(fallback.loda_submitted_by);
    let miner_metrics_listen_port: u16 = custom.miner_metrics_listen_port.unwrap_or(fallback.miner_metrics_listen_port);
    let loda_patterns_repository: String = custom.loda_patterns_repository.unwrap_or(fallback.loda_patterns_repository);
    let loda_outlier_programs_repository: String = custom.loda_outlier_programs_repository.unwrap_or(fallback.loda_outlier_programs_repository);
    let miner_program_upload_endpoint: String = custom.miner_program_upload_endpoint.unwrap_or(fallback.miner_program_upload_endpoint);
    let miner_filter_mode: MinerFilterMode = custom.miner_filter_mode.unwrap_or(fallback.miner_filter_mode);
    let miner_cpu_strategy: MinerCPUStrategy = custom.miner_cpu_strategy.unwrap_or(fallback.miner_cpu_strategy);
    let arc_repository_data: String = custom.arc_repository_data.unwrap_or(fallback.arc_repository_data);
    let loda_arc_challenge_repository: String = custom.loda_arc_challenge_repository.unwrap_or(fallback.loda_arc_challenge_repository);
    Config {
        basedir: basedir,
        loda_programs_repository: simpleenv.resolve_path(&loda_programs_repository),
        oeis_stripped_file: simpleenv.resolve_path(&oeis_stripped_file),
        oeis_names_file: simpleenv.resolve_path(&oeis_names_file),
        loda_rust_repository: simpleenv.resolve_path(&loda_rust_repository),
        loda_rust_executable: simpleenv.resolve_path(&loda_rust_executable),
        miner_sync_executable_command_windows: miner_sync_executable_command_windows,
        miner_sync_executable: simpleenv.resolve_path(&miner_sync_executable),
        loda_cpp_executable: simpleenv.resolve_path(&loda_cpp_executable),
        loda_submitted_by: loda_submitted_by,
        miner_metrics_listen_port: miner_metrics_listen_port,
        loda_patterns_repository: simpleenv.resolve_path(&loda_patterns_repository),
        loda_outlier_programs_repository: simpleenv.resolve_path(&loda_outlier_programs_repository),
        miner_program_upload_endpoint: miner_program_upload_endpoint,
        miner_filter_mode: miner_filter_mode,
        miner_cpu_strategy: miner_cpu_strategy,
        arc_repository_data: simpleenv.resolve_path(&arc_repository_data),
        loda_arc_challenge_repository: simpleenv.resolve_path(&loda_arc_challenge_repository),
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;
    use std::fs;
    use std::error::Error;
    use std::fmt;
    
    #[test]
    fn test_10000_expand_homedir() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_10000_expand_homedir");
        fs::create_dir(&homedir)?;
        let subdir = homedir.join("subdir");
        let simpleenv = SimpleEnvironment::new(homedir);

        // Act
        let resolved_path: PathBuf = simpleenv.resolve_path(&"$HOME/subdir".to_string());

        // Assert
        let subdir_string: String = subdir.to_str().unwrap().to_string();
        let resolved_string: String = resolved_path.to_str().unwrap().to_string();
        assert_eq!(subdir_string, resolved_string);
        assert_eq!(resolved_string.contains("$HOME"), false);
        assert_eq!(resolved_string.ends_with("/subdir"), true);
        Ok(())
    }

    #[test]
    fn test_10001_absolute_path() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_10001_absolute_path");
        fs::create_dir(&homedir)?;
        let subdir = homedir.join("subdir");
        let simpleenv = SimpleEnvironment::new(homedir);
        let subdir_string: String = subdir.to_str().unwrap().to_string();

        // Act
        let resolved_path: PathBuf = simpleenv.resolve_path(&subdir_string);

        // Assert
        let resolved_string: String = resolved_path.to_str().unwrap().to_string();
        assert_eq!(subdir_string, resolved_string);
        assert_eq!(resolved_string.contains("$HOME"), false);
        assert_eq!(resolved_string.ends_with("/subdir"), true);
        Ok(())
    }

    #[derive(Clone, Debug)]
    enum CheckSuffixError {
        WrongSuffix(String)
    }

    impl fmt::Display for CheckSuffixError {
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            match self {
                CheckSuffixError::WrongSuffix(message) => {
                    return write!(f, "CheckSuffixError: {}", message)
                }
            }
        }
    }

    impl Error for CheckSuffixError {}

    fn assert_has_suffix(path: &Path, expected_suffix: &str) -> Result<(), CheckSuffixError> {
        let path_string: String = path.to_str().expect("Expected Some, but got None").to_string();
        if !path_string.ends_with(expected_suffix) {
            let message = format!("Expected suffix {:?}, but got {:?}", expected_suffix, path_string);
            return Err(CheckSuffixError::WrongSuffix(message));
        }
        Ok(())
    }

    #[test]
    fn test_20000_assert_has_suffix() -> Result<(), Box<dyn Error>> {
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_20000_assert_has_suffix");
        fs::create_dir(&homedir)?;
        let result_ok = assert_has_suffix(&homedir, "/test_20000_assert_has_suffix");
        assert!(result_ok.is_ok());
        let result_err = assert_has_suffix(&homedir, "/no-such-thing");
        assert!(result_err.is_err());
        Ok(())
    }

    #[test]
    fn test_30000_fallback_config() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_30000_fallback_config");
        fs::create_dir(&homedir)?;
        let basedir = PathBuf::from(Path::new("non-existing-basedir"));

        // Act
        let config: Config = config_from_toml_content(Config::default_config(), basedir, homedir);

        // Assert
        assert_eq!(config.basedir.to_str().unwrap(), "non-existing-basedir");
        assert_has_suffix(&config.loda_programs_repository, "/loda/programs")?;
        assert_has_suffix(&config.oeis_stripped_file, "/loda/oeis/stripped")?;
        assert_has_suffix(&config.oeis_names_file, "/loda/oeis/names")?;
        assert_has_suffix(&config.loda_rust_repository, "/git/loda-rust")?;
        assert_has_suffix(&config.loda_rust_executable, "/git/loda-rust/rust_project/target/release/loda-rust")?;
        assert_eq!(config.miner_sync_executable_command_windows, "ruby");
        assert_has_suffix(&config.miner_sync_executable, "/git/loda-rust/script/miner_sync_simple.rb")?;
        assert_has_suffix(&config.loda_cpp_executable, "/loda/bin/loda")?;
        assert_eq!(config.loda_submitted_by, "John Doe");
        assert_eq!(config.miner_program_upload_endpoint, "http://api.loda-lang.org/miner/v1/programs");
        assert_eq!(config.miner_metrics_listen_port, 8090);
        assert_has_suffix(&config.loda_patterns_repository, "/git/loda-patterns")?;
        assert_has_suffix(&config.loda_outlier_programs_repository, "/git/loda-outlier-programs")?;
        assert_has_suffix(&config.arc_repository_data, "/git/arc-dataset-collection/dataset")?;
        assert_has_suffix(&config.loda_arc_challenge_repository, "/git/loda-arc-challenge")?;
        assert_eq!(config.miner_filter_mode, MinerFilterMode::New);
        assert_eq!(config.miner_cpu_strategy, MinerCPUStrategy::Max);
        Ok(())
    }

    #[test]
    fn test_40000_override_loda_submitted_by() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_40000_override_loda_submitted_by");
        fs::create_dir(&homedir)?;
        let content = 
        r#"
        loda_submitted_by = "Leonardo di ser Piero da Vinci"
        "#;
        let basedir = PathBuf::from(Path::new("non-existing-basedir"));

        // Act
        let config: Config = config_from_toml_content(content.to_string(), basedir, homedir);

        // Assert
        assert_eq!(config.loda_submitted_by, "Leonardo di ser Piero da Vinci");
        Ok(())
    }

    #[test]
    fn test_40001_override_loda_programs_repository() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_40001_override_loda_programs_repository");
        fs::create_dir(&homedir)?;
        let repodir = homedir.join("the-loda-programs-repo");
        fs::create_dir(&repodir)?;
        let content = 
        r#"
        loda_programs_repository = "$HOME/the-loda-programs-repo"
        "#;
        let basedir = PathBuf::from(Path::new("non-existing-basedir"));

        // Act
        let config: Config = config_from_toml_content(content.to_string(), basedir, homedir);

        // Assert
        assert_has_suffix(&config.loda_programs_repository, "/the-loda-programs-repo")?;
        assert!(config.loda_programs_repository.is_absolute());
        assert!(config.loda_programs_repository.is_dir());
        Ok(())
    }

    #[test]
    fn test_40002_override_miner_filter_mode() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_40002_override_miner_filter_mode");
        fs::create_dir(&homedir)?;
        let content = 
        r#"
        [miner_filter_mode]
        type = "all"
        "#;
        let basedir = PathBuf::from(Path::new("non-existing-basedir"));

        // Act
        let config: Config = config_from_toml_content(content.to_string(), basedir, homedir);

        // Assert
        assert_eq!(config.miner_filter_mode, MinerFilterMode::All);
        Ok(())
    }

    #[test]
    fn test_40003_override_miner_cpu_strategy() -> Result<(), Box<dyn Error>> {
        // Arrange
        let tempdir = tempfile::tempdir().unwrap();
        let homedir = PathBuf::from(&tempdir.path()).join("test_40003_override_miner_cpu_strategy");
        fs::create_dir(&homedir)?;
        let content = 
        r#"
        [miner_cpu_strategy]
        type = "cpu"
        [miner_cpu_strategy.content]
        count = 8
        "#;
        let basedir = PathBuf::from(Path::new("non-existing-basedir"));

        // Act
        let config: Config = config_from_toml_content(content.to_string(), basedir, homedir);

        // Assert
        assert_eq!(config.miner_cpu_strategy, MinerCPUStrategy::CPU {count: 8});
        Ok(())
    }
}